cannalee90 / flash-card

Flashcard web application
4 stars 0 forks source link

component생명주기 다시공부 #41

Open cannalee90 opened 6 years ago

cannalee90 commented 6 years ago

뭔가 잘못알고 있었던 점이 있었던거 같다

cannalee90 commented 6 years ago

https://legacy.gitbook.com/book/developmentarc/react-indepth/details

cannalee90 commented 6 years ago

어렴풋이 알고있었던거 다시 정리

  1. componentWillMount()에서 defaultProps에서 stateProps가 넘어오는줄 알았는데, 문서를 다시 읽어보니까 애초에 connect()함수가 HOC니까 redux에 있는 props들이 처음부터 넘어오는 것이었다.

https://github.com/reactjs/react-redux/blob/428b67b2dbbf4b80ee2222f9393abfcabfd8aa76/src/connect/mergeProps.js#L3

cannalee90 commented 6 years ago
  1. componentDidMount()에서 fetch를 하도록 하는게 맞다. 서버사이드 렌더링을 할 경우 componentWillMount()가 호출되기 때문에 componentDidMount()에서 호출하는게 맞다.

https://hackernoon.com/where-to-integrate-api-calls-in-reactjs-componentwillmount-vs-componentdidmount-710085dc05c3

cannalee90 commented 6 years ago

1_sn-ftowp0_vvrbeuafecma

https://cdn-images-1.medium.com/max/2000/1*sn-ftowp0_VVRbeUAFECMA.png

cannalee90 commented 6 years ago

initilize construct()

state를 초기화 한다 defaultProps과 새로운 Props들을 머지한다 Component를 생성할때 딱 한번만 호출된다.

cannalee90 commented 6 years ago

Mounting

componentWillMount

render()

componentDidMount()

cannalee90 commented 6 years ago

Update

새로운 props를 받거나 state를 업데이트할때 발동

state가 업데이트 될때는 다음과 같이 호출된다

shouldComponentUpdate()

componentWillUpdate()

componentDidUpdate()

componentWillReceiveProps

shouldComponentUpdate componentWillUpdate render componentDidUpdate

가 실행된다

cannalee90 commented 6 years ago

Unmounting

cannalee90 commented 6 years ago

이상 https://hackernoon.com/reactjs-component-lifecycle-methods-a-deep-dive-38275d9d13c0 정리