If you open two tabs and one of this tab changes the state before the other one be opened, the second tab it will still initialize with the initValue that doesn't correspond anymore to the real value and if the second tabs change the state it will override the changes made by the first one.
Example:
Using the increment example in the README:
- Open the first tab and click to increment + 1
- Now open a second tab, it'll show the count as 0 and if you click increment it will "ignore" the first tab change and count as 1 again.
This is not very good when you state depends on the previous state
Possible Solution:
Maybe also save the state value on to use localStorage/sessionStorage and do?:
let initValue = checkOnLocalStorage() || initalState;
let [state, dispatch] = useReducer(reducer, initValue);
If you open two tabs and one of this tab changes the state before the other one be opened, the second tab it will still initialize with the
initValuethat doesn't correspond anymore to the real value and if the second tabs change the state it will override the changes made by the first one.Example:
Using the increment example in the README:
This is not very good when you state depends on the previous state
Possible Solution:
Maybe also save the state value on to use localStorage/sessionStorage and do?: