강의

멘토링

커뮤니티

Inflearn Community Q&A

insung9405538's profile image
insung9405538

asked

Learning React while making web games

6-3. componentDidUpdate

onClickRedo 질문

Written on

·

167

·

Edited

0

componentDidUpdate를 사용하지 않고

this.componentDidMount()를 다시 불러와서 실행시켜도

정상적으로 작동하는데 이건 권장하지 않는 방법인가요?

혹시 그 이유가 더 긴 라이프 라이클을 갖게 돼서 그런가요?

  onClickRedo = () => {
    this.setState({
      winNumbers: lottoNumbers(),
      winBalls: [],
      bonus: null,
      redo: false,
    })
    this.timeout = [];
    this.componentDidMount();
  }
react

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

setState를 하면 알아서 componentDidUpdate가 실행되는데 굳이 수동으로 다른 함수를 실행할 필요가 없죠

insung9405538님의 프로필 이미지
insung9405538
Questioner

아하 그렇군요

insung9405538's profile image
insung9405538

asked

Ask a question