Install
You have to installimmer and jotai-immer to use this feature.
atomWithImmer
atomWithImmer creates a new atom similar to the regular atom with a different writeFunction. In this bundle, we don’t have read-only atoms, because the point of these functions is the immer produce(mutability) function.
The signature of writeFunction is (get, set, update: (draft: Draft<Value>) => void) => void.
Examples
Check this example with atomWithImmer:withImmer
withImmer takes an atom and returns a derived atom, same as atomWithImmer it has a different writeFunction.
Examples
Check this example with withImmer:useImmerAtom
This hook takes an atom and replaces the atom’swriteFunction with the new immer-like writeFunction like the previous helpers.
withImmer and atomWithImmer with useImmerAtom because they provide the immer-like writeFunction and we don’t need to create a new one.
You can use useSetImmerAtom if you need only the setter part of useImmerAtom.