강의

멘토링

커뮤니티

Inflearn Community Q&A

yahoo23447340's profile image
yahoo23447340

asked

Learning React while making web games

5-6. Comparison of class and hook life cycles

useEffect 질문있습니다.

Written on

·

225

0

    useEffect(() => {  // componentDidMount, componentDidUpdate = 합쳐놓았다고 생각
        console.log('랜덤')
        interval.current = setInterval(changeHand, 100)
        return () => {  // componentWillUnmount
            console.log('랜덤종료')
            clearInterval(interval.current)
        }
    }, [imgCoord])  // componentDidUpdate

componentwillMount가 헷갈리는게

componentDidMount, componentDidUpdate 이후에 바로 실행이 되는건가요~?

아니면 componentDidUpdate가 되면서 기존 컴포넌트가 리렌더링 될 때 일어나나요? 궁금합니다.

react

Answer 2

1

zerocho님의 프로필 이미지
zerocho
Instructor

새로운 useEffect가 실행되기 직전에 발생합니다.

0

yahoo23447340님의 프로필 이미지
yahoo23447340
Questioner

useEffect에서 componentwillUnMount인데 오타가 났네요... useEffect의 작업이 끝난후 바로 return이 실행되나요?

yahoo23447340's profile image
yahoo23447340

asked

Ask a question