3 ms·
This is a footgun I found at a few Amazon internal apps recently. I was able to clear away probably 3/4 uses of useEffect--some of which I was guilty of adding.
by Gunax 4y ago
This is a footgun I found at a few Amazon internal apps recently. I was able to clear away probably 3/4 uses of useEffect--some of which I was guilty of adding.
Given how common this error is, there is definitely an unmet need. What people want is a listener, ie.:
- recalculate a var whenever a prop changes (this is what useMemo is for)
- trigger a function when a state changes (should be moved to the function that changed the state)
- gardenhedge 4y agoThat is not what useMemo is for. It's for caching a result and only recalculating it if the dependencies have changed. The aim is to optimize performance. It is not intended for listening to prop changes.