I have a child component which is a Redux form and from it's handleSubmit method, I need to call a method on the Parent Component. I try to do this by passing a callback as props from the Parent and nothing happens.
I've seen that this method works only when a function is called directly with an event handler on the child component.
import Parent from './parent.js';
class Child extends React.Component {
constructor(props) {
super(props);
};
callCloseModal = () => {
this.props.closeModal();
}
handleFormSubmit (values) {
this.callCloseModal()
}
render() {
<form onSubmit=
{handleSubmit(this.handleFormSubmit.bind(this))}>
.....
</form>
}
}
class Parent extends React.Component {
constructor (props) {
super(props)
this.state = {
modalOpen: false,
}
}
.....
handleModalClose() {
this.setState({ modalOpen: false })
}
render() {
<Child closeModal={this.handleModalClose}> {this.props.children}</Child>
}
}
How can I call a method on the parent component from a method on a child component?
Edit: The method was correct but it was one level higher (Grandparent component)