-
nomard) Clean Up 함수React 2023. 3. 16. 16:45
Clean UP.
: useEffect( 함수 , [] ) 를 사용할 때 변하는 값을 지정하지 않으면 해당 함수는 생성될 때 한번 작동하고 끝이다.
다음과 같은 함수를 해당 컴포넌트가 없어질 때 특정 함수가 작동하게 만드는 것이 Clean Up 함수이다.
function something() { useEffect( () => { console.log("Hi"); return () => console.log("bye"); }, []); }; -> something 함수가 다른곳에서 불리면 console.log("Hi")를 실행하고, something 함수가 제거되면 console.log("bye")를 실행한다.
'React' 카테고리의 다른 글
OPEN API 데이터 불러오기 ( fetch ) (0) 2023.03.19 nomad) react .map( ) (0) 2023.03.17 nomad) react useState( [] ) 활용 (0) 2023.03.17 nomard) React 설치 및 연결 (0) 2023.03.16 nomard) ReactJS 기본, useState, Component, props (0) 2023.03.13