1class Parent extends React.Component {
2 state = { message: "" }
3 callbackFunction = (childData) => {
4 this.setState({message: childData})
5 },
6 render() {
7 return (
8 <div>
9 <Child1 parentCallback = {this.callbackFunction}/>
10 <p> {this.state.message} </p>
11 </div>
12 );
13 }
14}
15
16class Child1 extends React.Component{
17 sendData = () => {
18 this.props.parentCallback("Hey Popsie, How’s it going?");
19 },
20 render() {
21 //you can call function sendData whenever you'd like to send data from child component to Parent component.
22 }
23};
1Parent:
2
3<div className="col-sm-9">
4 <SelectLanguage onSelectLanguage={this.handleLanguage} />
5</div>
6
7Child:
8
9handleLangChange = () => {
10 var lang = this.dropdown.value;
11 this.props.onSelectLanguage(lang);
12}