可以自己写一个公用Hook来储存
function usePrevious(value) {
const ref = useRef()
useEffect(() => {
ref.current = value
})
return ref.current
}
使用:
const oldValue = usePrevious(value)
可以自己写一个公用Hook来储存
function usePrevious(value) {
const ref = useRef()
useEffect(() => {
ref.current = value
})
return ref.current
}
使用:
const oldValue = usePrevious(value)