Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes bad intermediate return values from
useStoreDependency
Fixes an issue where `useStoreDependency` would return an incorrect intermediate value when a prop change causes the dependency value to change. Now the updated value is returned immediately when the dependency value changes, rather than being set in state but not returned until the next render cycle. === Before The render cycle for a prop change looked like this: 1. component renders: `useStoreDependency` calculates the value, stores it in initial state, and returns it 2. prop change causes component to re-render: `useStoreDependency` calculates new value; if the value changed from (1): stores the new value in state, __but returns the old cached value from (1)__. 3. internal setState call causes component to re-render: `useStoreDependency` calculates new value, but the value doesn't change (props are same as in (2)): finally returns the new value. === After The render cycle is the same as above, except (2) returns the updated value immediately instead of the outdated cached value from (1) Signed-off-by: Gordon McNaughton <[email protected]>
- Loading branch information