useLocalStore model not updated based on dependency
@ctrlplusb
I tried your example here: https://easy-peasy.now.sh/docs/api/use-local-store.html
And from a parent I send in a product prop that I force changes on, and it seems that local store model does not get recreated when the prop is added as a dependency.
I debugged the code, and I believe the issue is in use-local-store.js
const [currentState, setCurrentState] = useState(() => store.getState());
Because of how that is set, it always keeps returning the same state value even if one of the dependencies forces the useMemoOne function to execute.
The only time we get a new state is when the store.subscribe(..) kicks off due to an action fired on the model return store.subscribe(() => { const nextState = store.getState(); console.log('store changes', nextState); if (currentState !== nextState) { setCurrentState(nextState);👈🏽 // only time state gets updated and hook returns the caller an updated state } });
I am not sure this is how it's supposed to work, but definitely defeats the purpose of a DEP array, if the return, [state, actions, store] isn't updated to reflect the new model.
Hi @rmcarias
Have you tried 5.0.0-alpha.2?
This is still a problem in 5.0.3.
Pull request https://github.com/ctrlplusb/easy-peasy/pull/685 includes a fix and a test case.