Reputation: 16202
When my react-native app launches, I need to fetch data from a remote API. Should I trigger this in the componentDidMount
method of my main component? Are there other recommended options?
Additionally, does React provide a way to keep track of all outstanding network calls (ie, unresolved Promises), and a way to cancel them if needed? Or would this be considered the programmer's responsibility, so that I would need to write the code myself or use another library for it?
Upvotes: 4
Views: 1688
Reputation: 53681
Jonah,
Yes, this should probably be done in the componentDidMount. When the response arrives, store the data in state (this will trigger a render to update your UI).
I am not aware of a way to keep track of all outstanding network calls. We've been handling this ourselves.
Upvotes: 3