-
- useEffect
: api 처럼 렌딩할 때 불러들였던 정보를 다시는 부르고 싶지 않을 때 ( 한번만 불러도 될 때 ) 사용한다.
어떤 로그들은 렌딩할 때 다 같이 렌딩 된다. 하지만 같은 데이터가 주어질 때 거부하는 방법이 있다.
useEffect( 실행하고싶은함수 , [keyword] ); -> keyword의 값이 변할 때만 함수를 실행시킨다. 이를 이용해서 api를 처음 한 번만 불러오는 등 함수의 실행을 제어할 수 있다. useEffect( 실행하고싶은함수 , [] ); -> 키워드에 값이 없으면 한번만 실행하고 다시 실행할 수 없다.
*** Create React App 의 index.js 에는
<React.StrictMode><App /></React.StrictMode>의 형식으로 App을 불러들인다. 따라서 새로고침 할 경우 app의 랜더링이 항상 2번씩 된다.
( 이는 렌더링 오류를 방지한다. )
'React' 카테고리의 다른 글
git hub를 이용해 웹 사이트 배포하기 (0) 2023.03.21 React Router ( parameters ) (0) 2023.03.20 React Router (ver. 6 이상) (0) 2023.03.19 OPEN API 데이터 불러오기 ( fetch ) (0) 2023.03.19 nomad) react .map( ) (0) 2023.03.17