Reputation: 23
I need to reload the data from api once state changed. Is is possible to fetch data again with getInitialProps on client side?
Upvotes: 1
Views: 878
Reputation: 96
Why don't you fetch the data on the componentDidMount?
componentDidMount() {
yourAPI.fetch().then((pFetchData) => {
this.setState({data: pFetchData});
});
}
In practice, componentDidMount is the best place to put calls to fetch data, for two reasons:
https://www.codeproject.com/Articles/1177776/Where-to-Fetch-Data-componentWillMount-vs-componen
Hope it helps :)
Upvotes: 2