deno.land / x / jotai@v1.8.4 / src / immer / atomWithImmer.ts
12345678910111213141516171819202122232425import { produce } from 'immer'import type { Draft } from 'immer'import { atom } from 'jotai'import type { WritableAtom } from 'jotai'
export function atomWithImmer<Value>( initialValue: Value): WritableAtom<Value, Value | ((draft: Draft<Value>) => void)> { const anAtom: any = atom( initialValue, (get, set, fn: Value | ((draft: Draft<Value>) => void)) => set( anAtom, produce( get(anAtom), typeof fn === 'function' ? (fn as (draft: Draft<Value>) => void) : () => fn ) ) )
return anAtom}
Version Info