I tried the sample code of useReducer:
const initialState = { count: 0 };
function reducer(state, action) {
switch (action.type) {
case "increment":
return { count: state.count + 1 };
case "decrement":
return { count: state.count - 1 };
default:
throw new Error();
}
}
export default function Counter() {
const [state, dispatch] = useReducer(reducer, initialState);
// ...
and instantiated 3 Counters in the App. Sample on: https://codesandbox.io/s/serene-morse-c017r
So it seems the state is local to each Counter component, and is not the "single source of truth" like on Redux? If the App wants to get the value of all counters, or one Counter wants to get the value of another Counter, how would that be done?