Currently each new ClassState is created when using useReducer.
Furthermore, all the ClassStates are created in the parent-components.
If we want to get the ClassState in the child-components, then
we need to pass it with props.
It is better to have a shared state by ReducerModuleFunc,
and re-render the components if the corresponding ClassState is updated.
Therefore, given ReducerModuleFuncA, ClassStateA, ParentComponent, ChildComponent, and GrandChildComponent:
- If we
useReducer(ReducerModuleFunc) in ParentComponent, ChildComponent, and GrandChildComponent,
for the same id, they should be able to access the same state.
- If some dispatch is triggered in
GrandChildComponent, then ParentComponent, ChildComponent, and GrandChildComponent should all be re-rendered.
- For simplicity, ideally only the
id is passed through the components. However, this may violate the reactjs principle.