react-localize-redux
react-localize-redux copied to clipboard
onChange in handleChange is called on every change to store
Do you want to request a feature or report a bug? bug What is the current behavior? Any change to the redux store cause the onChange function to be executed. This causes our app to slow down a lot.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
What is the expected behavior? For the onChange to only be called when the localize part of the state is changed
Which versions of react
and react-localize-redux
are you using?
react: 16.8.6
reat-localize-redux: 7.0.3
redux: 4.0.1
Redux suggest something like this function observeStore(store, select, onChange) { let currentState;
function handleChange() { let nextState = select(store.getState()); if (nextState !== currentState) { currentState = nextState; onChange(currentState); } }
let unsubscribe = store.subscribe(handleChange); handleChange(); return unsubscribe; }
https://github.com/reduxjs/redux/issues/303#issuecomment-125184409