Open chalu opened 2 months ago
This doesn't seem like an Immer question per se.
Is this being used with React? With Redux? Some other library?
Normally Immer is used to create a new state value, but the actual value is then stored and managed in whatever state management tool is appropriate (useState / useReducer
for React, createSlice
for Redux, etc).
This doesn't seem like an Immer question per se.
Is this being used with React? With Redux? Some other library?
Normally Immer is used to create a new state value, but the actual value is then stored and managed in whatever state management tool is appropriate (
useState / useReducer
for React,createSlice
for Redux, etc).
It is being used in a vanilla HTML/CSS/Typescript frontend application that wants to centralize and better manage state like in modern frontend apps.
Immer doesn't know or care how you're "storing" the state. It's a function that calculates a new state, immutably. It's up to you to save that result somewhere, just like you would any other value you've calculated.
Immer doesn't know or care how you're "storing" the state. It's a function that calculates a new state, immutably. It's up to you to save that result somewhere, just like you would any other value you've calculated.
This clears things for me. Thanks
🙋♂ Proper Way To Get Current State
What is the proper way of getting the current state with immer. Do you reassign the output of produce to the state or use something else like "current" which can be imported from the immer package?
Does reassigning not negate the immutability practice of Immer, especially if using Typescript and the state was defined as read-only to enforce immutability. This has not been clear to me from the documentation, hence the question :