I have a higher-order component FormBuilder like this:
const FormBuilder = (WrappedComponent) => {
return class HOC extends React.Component {
clearForm() { // ... }
render() {
return (
<Form onSubmit={//what do I say here?!}>
<Form.Input placeholder='Name' name='name' />
<WrappedComponent clearForm={this.clearForm} />
<Form>
);
}
}
}
And here is the WrappedComponent NewPizzaForm:
class WrappedComponent extends React.Component {
onSubmit() { // sends a POST request to the backend, then this.props.clearForm() }
render() {
return (
<Form.Button>Add Pizza</Form.Button>
);
}
}
const NewPizzaForm = FormBuilder(WrappedComponent);
export default NewPizzaForm;
So I want to send the onSubmit function as a prop from the WrappedComponent to the FormBuilder so that it is available for call when the form is submitted. And the reason I decided to define the onSubmit function inside WrappedComponent is because I have another WrappedComponent(uses FormBuilder) that has the onSubmit function but it sends a PATCH request rather than POST request. How do I achieve this?