deno.land / x / jotai@v1.8.4 / src / utils / useResetAtom.ts

useResetAtom.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { useCallback, useContext } from 'react'import { SECRET_INTERNAL_getScopeContext as getScopeContext } from 'jotai'import type { WritableAtom } from 'jotai'import { WRITE_ATOM } from '../core/store'import { RESET } from './constants'
type Scope = NonNullable<Parameters<typeof getScopeContext>[0]>
export function useResetAtom<Value>( anAtom: WritableAtom<Value, typeof RESET>, scope?: Scope) { const ScopeContext = getScopeContext(scope) const store = useContext(ScopeContext).s const setAtom = useCallback( () => store[WRITE_ATOM](anAtom, RESET), [store, anAtom] ) return setAtom}
jotai

Version Info

Tagged at
2 years ago