4 ms·
I don't think you need it - since you're deriving state from props you can just derive from the new props and compare to the old state. At least I believe that'
by marcins 9y ago
I don't think you need it - since you're deriving state from props you can just derive from the new props and compare to the old state. At least I believe that's the reasoning.
- aravindet 9y agoIn my use case, the component receives the URL of a resource as a prop, and it re-fetches the resource from a backend when the URL changes. I'd like to avoid the expensive fetch when it's some other prop that changed. Copying the URL to the state will work, although it's a bit more verbose.
- marcins 9y agoThat's probably something that belongs in `componentDidUpdate`, you'll have access to `prevProps` there to compare whether you need to trigger a new fetch. I don't believe that `getDerivedStateFromProps` should have any side-effects.