related links:how-to-pass-data-from-child-component-to-its-parent-in-reactjs
In Parent Component:
getData(val) {
// do not forget to bind getData in constructor
console.log(val);
}
render() {
return(<Child sendData={this.getData}/>);
}
In Child Component:
demoMethod() {
this.props.sendData(value);
}
The proposed solution is to use a function property to pass the value from the child to parent component.
This is how the elementUI library code look like:
class Example extends Component{
//constructor()
this.state={
value:''
}
}
render() {
return (
<Input value={this.state.value}></Input>
);
}
In elementUI they pass a variable and not a function.
How does elementUI make the child and parent component have a two-way data binding?