UNPKG

@loke/ui

Version:
2 lines (1 loc) 272 B
import{useMemo,useRef}from"react";function usePrevious(value){let ref=useRef({previous:value,value});return useMemo(()=>{if(ref.current.value!==value)ref.current.previous=ref.current.value,ref.current.value=value;return ref.current.previous},[value])}export{usePrevious};