import { atom , useAtom , WritableAtom } from 'jotai' ; import { useMemo } from 'react' ; import { _hexxScope } from '../constants/atom' ; export function useUpdateAtom < Value , Update > ( anAtom ) { const writeOnlyAtom = useMemo ( ( ) => { return atom ( null , ( _get , set , update ) => set ( anAtom , update ) ) ; } , [ anAtom ] ) ; writeOnlyAtom . scope = anAtom . scope ; return useAtom ( writeOnlyAtom ) [ 1 ] ; } export function useNullableAtom < T = unknown , A = unknown > ( at ? ) { let atomValue = at ; if ( ! atomValue ) { atomValue = atom ( null ) ; atomValue . scope = _hexxScope ; } return useAtom ( atomValue ) ; }