I am passing object from parent componet to child component and there some input fields in child component which handled in parent component as follow:
import React, { Component } from "react";
import Child from 'path';
class parent extends Component {
constuctor(props){
super(props);
this.state = {
obj :{
//object
}
}
this.handlerInput = this.handlerInput.bind(this);
}
handlerInput(e){
//logic to update state obj
}
render(){
return(
<div className="content">
<Child changeHandle={this.handlerInput} />
</div>
);
};
}
export default parent;
import React, { Component } from "react";
class Child extends Component {
render(){
return(
<div className="content">
<input type="text" onChange={ this.props.changeHandle } name="xyz" />
</div>
);
};
}
export default Child;
Now lets suppose if i have to use child component at multiple places so every time i have to define changeHandle function in parent component?
Any suggestion to update parent state from child ?