Component가 마운트 되면 constructor()getDerivedStateFromProps에서 props와 state를 비교render()componentDidMount()update 시에는getDerivedStateFromProps에서 props와 state
위와 같은 App 컴포넌트가 있을 때,button을 클릭했을 경우 alert를 뜨게 하고 싶으면Vanilla JS의 경우에는이런식으로 하면 되고리액트의 경우에는이런식으로 하면 될 것 같지만 사실은 rendering이 될 때 함수 호출 결과가 onClick에 바인딩 되기
useState,useEffect Hook 말고도 여러가지가 더 있고 커스텀해서도 할 수는 있지만여기서는 아까 말한 두 가지를 다뤄보고자 한다.React에서 Hook을 구현하는 핵심은 바로 Closure다.클로저를 간단히 만들어보면setCount의 값으로 2를 집어넣었
출처: https://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/ 마운트가 될 때 발생하는 생명주기constructor getDerivedStateFromPropsrendercomponentDidMount