UNPKG

678 BTypeScriptView Raw
1import { useSetAtom } from 'jotai';
2import type { Setter, WritableAtom } from 'jotai';
3type Scope = NonNullable<Parameters<typeof useSetAtom>[1]>;
4type WriteGetter = Parameters<WritableAtom<unknown, unknown>['write']>[0];
5type Callback<Result, Arg> = undefined extends Arg ? (arg?: Arg) => Result : (arg: Arg) => Result;
6export declare function useAtomCallback<Result, Arg>(callback: (get: WriteGetter, set: Setter, arg: Arg) => Promise<Result>, scope?: Scope): Callback<Promise<Result>, Arg>;
7export declare function useAtomCallback<Result, Arg>(callback: (get: WriteGetter, set: Setter, arg: Arg) => Result, scope?: Scope): Callback<Result | Promise<Result>, Arg>;
8export {};