I have class which makes an api call, and sets the response data as the state value like so
export class TestClass extends React.Component {
state = {
data: null
}
componentDidMount(){
fetch('http://www.nfl.com/feeds-
rs/bigPlayVideos/2018/REG/1.json')
.then(response => response.json())
.then(res => this.setState({ data: res.bigPlays }))
}
The above code works and sets the state correctly. Then in the render i pass the properties like so.
render (){
const {data} = this.state;
return (
<div>
<ChildComponent data={data} />
</div>
)
}
My Child component looks like so
componentDidMount(){
const {data} = this.props
}
The data prop comes in correctly in the render after the page updates but comes in as null in the componentDidMount. I need to do some further state updates, so is there anyway i can get access to the values in the componentDidMount(), if not where would be the best place to do further state logic in the ChildComponent class.
Any help is much appreciated, thanks.