목록useState (1)
코딩쌀롱

useState의 지연 초기화를 통해 리액트 함수 컴포넌트를 최적화시킬 수 있다. // 예제 1 const Counter = () => { const [count, setCount] = useState( Number.parseInt(window.localStorage.getItem(cacheKey)), ) useEffect(() => { window.localStorage.setItem(cacheKey, count) }, [cacheKey, count]) return ( Count: {count} setCount((prevCount) => prevCount - 1)}>- setCount((prevCount) => prevCount + 1)}>+ ) } // 예제 2 const Counter = () =>..
개발공부
2021. 4. 30. 03:15