I'm currently implementing global state handling in React using the Context API in combination with the useReducer hook.
I have two concerns regarding mutability:
- When updating state in my reducers, do I need to e.g use Lodash's
cloneDeepfunction to sever the reference between the objects going into my reducer and the stored state? - Is it possible to ruin the global state by manually mutating it outside reducers, or will it behave like "normal React state" in the sense that manual mutations will get overwritten during the next update cycle?
For reference: docs