deno.land / x / jotai@v1.8.4 / src / core / useAtom.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import 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), ]}
Version Info