react lifecycle
일단 사용해보고, 많이 사용하는 위주로 천천히 업데이트
마운트 시
constructor()
- 제일 먼저 super(props)를 호출
- state 초기화 작업
- 인스턴스에 이벤트 바인딩(this.{이벤트명} = this.{이벤트명}.bind(this))
이벤트 내에서 this 를 쓰기위함.
하지만 이벤트를 es6 로 구현하면 필요 없음..
render()
- 화면을 그리는 역할
- setState 나 그런 작업보다 분기로 하여 화면을 그리는 역할에 지충.
componentDidMount()
- component가 mount 되고 나서 실행
- 보통 외부 요청할때 많이 사용
- 주로 setState 가 일어나는 곳.
마운트 해제
componentWillUnmount()
- component를 벗어날때(페이지를 벗어날떄), 실행
참조
https://ko.reactjs.org/docs/react-component.html
http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/
마운트 시
constructor()
- 제일 먼저 super(props)를 호출
- state 초기화 작업
- 인스턴스에 이벤트 바인딩(this.{이벤트명} = this.{이벤트명}.bind(this))
이벤트 내에서 this 를 쓰기위함.
하지만 이벤트를 es6 로 구현하면 필요 없음..
render()
- 화면을 그리는 역할
- setState 나 그런 작업보다 분기로 하여 화면을 그리는 역할에 지충.
componentDidMount()
- component가 mount 되고 나서 실행
- 보통 외부 요청할때 많이 사용
- 주로 setState 가 일어나는 곳.
마운트 해제
componentWillUnmount()
- component를 벗어날때(페이지를 벗어날떄), 실행
참조
https://ko.reactjs.org/docs/react-component.html
http://projects.wojtekmaj.pl/react-lifecycle-methods-diagram/
댓글
댓글 쓰기