usePrevious

export default function Index() { const [count, setCount] = useState(0); const PrevCountRef = useRef(); useEffect(() => { console.log("work"); PrevCountRef.current = count; }); const PrevCount = PrevCountRef.current; console.log(count, PrevCount); return ( Now :{count} Before : {PrevCount} setCount(count + 1)}> up ); } 프로젝트를 진행하면서 이전 state값을 알아야 하는 경우가 발생했다. 공식 문서에서는 위의 예제와 같이 알려주고 있었다. function..
helloyukyung
'usePrevious' 태그의 글 목록