deno.land / x / jotai@v1.8.4 / src / immer / atomWithImmer.ts

atomWithImmer.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { 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}
jotai

Version Info

Tagged at
2 years ago