로딩
요청 처리 중입니다...

react native useRef 핵심요약

 react native useRef 핵심요약

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 (

{count}

setCount(c=>c+1)}>+ } ///unmount 시 출력 count값 useEffect함수 내부에 return 키워드를 사용하여 정리 및 마지막 호출하는 느낌...