본문 바로가기
Web & Mobile/React.js

React Hooks LifeCycle 요약

by Bennyziio 2021. 6. 22.
반응형

ComponentDidMount

  1. //Class
  2. componentDidMount() {
  3. console.log('I just mounted!');
  4. }
  5.  
  6. //Hooks
  7. useEffect(() => {
  8. console.log('I just mounted!');
  9. }, [])

 

ComponentWillUnmount

  1. //Class
  2. componentWillUnmount() {
  3. console.log('I am unmounting');
  4. }
  5.  
  6. //Hooks
  7. useEffect(() => {
  8. return () => console.log('I am unmounting');
  9. }, [])

 

ComponentWillReceiveProps

  1. //Class
  2. componentWillReceiveProps(nextProps) {
  3. if (nextProps.count !== this.props.count) {
  4. console.log('count changed', nextProps.count);
  5. }
  6. }
  7.  
  8. //Hooks
  9. useEffect(() => {
  10. console.log('count changed', props.count);
  11. }, [props.count])
반응형

댓글