Problem: I am unable to access child state from parent component.
My approach: I can access child state from the parent if I create the state in the parent.
Question: is there any other way if I don't want to create a state in parent component and just get the data from children and make an API call?
class Parent extends React.Component {
handleOnClick() {
client.POST('/post/name',childStateName);
}
render() {
return (
<Child />
<button onClick={this.handleOnClick}> save </button>
);
}
}
class Child extends React.Component {
constructor(props) {
super(props);
this.state = {name: 'srk'};
}
render() {
return (
{this.state.name}
);
}
}