I am trying to set the local state from a prop, like this:
constructor() {
super();
this.toggleDetails = this.toggleDetails.bind(this);
this.resetFields = this.resetFields.bind(this);
this.state = {
showDetails: [],
result: this.props.simulationResult.simulationResult,
};
}
And then pass it later in the render method to child components like this:
const { showDetails, result } = this.state;
<Table
showDetails={showDetails}
toggleDetails={this.toggleDetails}
result={result}
/>
I am receiving this prop with an api call in the mapStateToPros
method like this:
simulationResult: getSimulationResult(state),
I am not sure why do I get undefined, and how can I fix this so that I a can set the state in the class with the props?