렌더링 과정을 보시기 전에 리액트 훅의 동작에 대해 알고나면 이해가 훨씬 더 쉽습니다.
https://steady-snb.tistory.com/104
7. React Hooks의 정의와 종류에 대해 알아보자
React Hooks란?React 16.8버전부터 Hook이란 개념이 추가되었습니다.Hook은 함수형 컴포넌트에서 React state와 생명주기 기능을 제공해줍니다. React Hooks의 종류 기본적으로 리액트에서 제공하는 10가지
steady-snb.tistory.com
다음은 리액트 컴포넌트가 실행되는 과정을 알아보기위한 코드입니다.
import {useEffect,useState} from 'react';
function FunctionalComponent() {
console.log('Function Beginning');
const [value, setValue] = useState(0);
useEffect(() => {
console.log('Function useEffect[]');
return () => {
console.log('Function useEffect return[]');
}
},[]);
useEffect(() => {
console.log('Function useEffect[value]');
return () => {
console.log('Function useEffect return[value]');
}
},[value]);
console.log('Function End');
return (
<div>
<h1>FunctionalComponent</h1>
<h1>value: {value}</h1>
<button onClick={() => {
setValue((state) => state + 1)
}}
>
Increase value
</button>
</div>
);
}
export default FunctionalComponent
'IT지식 > 리액트(React) 공부' 카테고리의 다른 글
9. React로 아코디언(Accordion) 만들기 (0) | 2025.03.03 |
---|---|
7. React Hooks의 정의와 종류에 대해 알아보자 (0) | 2025.03.03 |
6.React Props를 활용하여 간단한 웹페이지 제작 (0) | 2025.03.02 |
5. React에서 State의 정의와 사용법 (0) | 2025.03.01 |
4. React에서 Props의 정의와 사용법 (0) | 2025.03.01 |