deno.land / x / jotai@v1.8.4 / src / core / useAtom.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { Atom, SetAtom, WritableAtom } from './atom'import type { ExtractAtomResult, ExtractAtomUpdate, ExtractAtomValue,} from './typeUtils'import { useAtomValue } from './useAtomValue'import { useSetAtom } from './useSetAtom'
type Scope = NonNullable<Parameters<typeof useAtomValue>[1]>
export function useAtom<Value, Update, Result extends void | Promise<void>>( atom: WritableAtom<Promise<Value>, Update, Result>, scope?: Scope): [Value, SetAtom<Update, Result>]
export function useAtom<Value>( atom: Atom<Promise<Value>>, scope?: Scope): [Value, never]
export function useAtom<Value, Update, Result extends void | Promise<void>>( atom: WritableAtom<Value, Update, Result>, scope?: Scope): [Awaited<Value>, SetAtom<Update, Result>]
export function useAtom<Value>( atom: Atom<Value>, scope?: Scope): [Awaited<Value>, never]
export function useAtom< AtomType extends WritableAtom<any, any, void | Promise<void>>>( atom: AtomType, scope?: Scope): [ Awaited<ExtractAtomValue<AtomType>>, SetAtom<ExtractAtomUpdate<AtomType>, ExtractAtomResult<AtomType>>]
export function useAtom<AtomType extends Atom<any>>( atom: AtomType, scope?: Scope): [Awaited<ExtractAtomValue<AtomType>>, never]
export function useAtom<Value, Update, Result extends void | Promise<void>>( atom: Atom<Value> | WritableAtom<Value, Update, Result>, scope?: Scope) { if ('scope' in atom) { console.warn( 'atom.scope is deprecated. Please do useAtom(atom, scope) instead.' ) scope = (atom as { scope: Scope }).scope } return [ useAtomValue(atom, scope), // We do wrong type assertion here, which results in throwing an error. useSetAtom(atom as WritableAtom<Value, Update, Result>, scope), ]}
jotai

Version Info

Tagged at
2 years ago