✔️ React의 Component는 클래스형과 함수형으로 구성
기존의 클래스형 컴포넌트에서는 몇 가지 어려움이 존재
함수형 컴포넌트에서 State와 Lifecycle 기능을 연동해주는 함수
❗️클래스형에서는 동작하지 않음
const [posts, setPosts] = useState([]); // 비구조화 할당 문법
➡️ useState([])와 같이 () 안에 초기화 설정 가능(예제는 빈 배열 생성 상태)
useEffect(() => {
console.log("렌더링 완료");
console.log(posts); // posts가 변경되어 리턴되면 useEffect 실행
});
➡️ 클래스 컴포넌트의 componentDidMount()와 componentDidUpdate()의 역할 동시에 한다고 봐도 됨
[참고 자료]