Skip to content

Instantly share code, notes, and snippets.

@yeonwooz
Last active August 29, 2021 13:00
Show Gist options
  • Save yeonwooz/9f67428ea3d9497d3479b99355acd78f to your computer and use it in GitHub Desktop.
Save yeonwooz/9f67428ea3d9497d3479b99355acd78f to your computer and use it in GitHub Desktop.
useEffect_when_updating
// dependency array - 주시하는 state가 없을 때
useEffect(() => {
logicForMounting() // 마운트, 리렌더링 될 때마다 실행
return () => {
logicForUnmounting() // 언마운트될 때, 리렌더링 될 때마다 실행
}
})
// dependency array [ state ] - 주시하는 state가 있을 때
useEffect(() => {
logicForMounting() // 마운트, 리렌더링 될 때마다, state 업데이트될 때마다 실행
return () => {
logicForUnmounting() // 언마운트될 때, 리렌더링 될 때마다, state 업데이트될 때마다 실행
}
}, [someState])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment