React cleanup

Created
Created
2021 Apr 5 12:44
Tags
Tags

return cleanup function - unmount

return function cleanup() { }
해당 코드는 처음 렌더링 될 때의 state를 출력해서 문제가 있다
마지막 state로 cleanup하려면 React의 re-render와 독립적인 ref의
React useRef()
를사용해야
const Conter = () =>{ const [count, setCount] = useState(0) const countRef = useRef(count) useEffect(() => { return () => { console.log("unmount 시 출력", countRef.current); } }, [])}
 
 

Recommendations