API calls in componentWillMount vs componentDidMount
Closed this issue · 3 comments
avbanks commented
Is there any reason API calls are made in WillMount as opposed to DidMount
If I'm reading this correctly the React docs say use DidMount:
"componentDidMount() is invoked immediately after a component is mounted. Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request. Setting state in this method will trigger a re-rendering."
https://facebook.github.io/react/docs/react-component.html
https://daveceddia.com/where-fetch-data-componentwillmount-vs-componentdidmount/
avbanks commented
Outstanding example app btw! I appreciate the quality!