import React, { useEffect, useState, useRef } from 'react'; const Conter = () =>{ const [count, setCount] = useState(0); const countRef = useRef(count); useEffect(() => { countRef.current = count; },[count]) // (1) 첫 번째 useEffect useEffect(() => { return () => { console.log("unmount 시 출력", countRef.current); }; }, []); // (2) 두 번째 useEffect return (
원문 링크 : react native useRef 핵심요약