facebookarchive / redux-react-hook

React Hook for accessing state and dispatch from a Redux store
MIT License
2.16k stars 103 forks source link

Bail in setDerivedState instead of keeping a ref #38

Closed ianobermiller closed 5 years ago

ianobermiller commented 5 years ago

Instead of keeping a ref to the last derived state, bail in setDerivedState by returning the same last derived state.

This simplifies the code and has the same effect. Note that I had to change the test to use useEffect to track "renders", since according to https://reactjs.org/docs/hooks-reference.html#bailing-out-of-a-state-update the bailout will still run the function body, but won't call effects or render children, which are the expensive things.