import { atom , useAtom } from 'jotai' ; import { useAtomValue , useUpdateAtom } from 'jotai/utils' ; export type PromiseFunc = ( ) => Promise < void > | void ; export interface PromiseObj { fn : PromiseFunc ; } export const noop = ( ) => { } ; export const atomFunc = ( ) => { return atom < PromiseObj > ( { fn : noop } ) ; } ; export type AtomFunc = ReturnType < typeof atomFunc > ; export const useAtomFunc = ( fnAtom ) => { const [ { fn } , setFn ] = useAtom ( fnAtom ) ; return [ fn , setFn ] ; } ; export const useUpdateAtomFunc = ( fnAtom ) => { return useUpdateAtom ( fnAtom ) ; } ; export const useAtomFuncValue = ( fnAtom ) => { return useAtomValue ( fnAtom ) ; } ;