import { useAtom , PrimitiveAtom } from 'jotai' ; import { useEffect , useRef } from 'react' ; export function usePreviousExistAtom ( atom ) { const [ value ] = useAtom ( atom ) ; const ref = useRef ( ) ; useEffect ( ( ) => { if ( value ) { ref . current = atom ; } } , [ value , atom ] ) ; return ref . current ; }