& side effect [React]
useEffect(() => {}, [])
์ปดํฌ๋ํธ ๋ด๋ถ์์ useEffect hook ์์ผ๋ก์จ => causing side effect in a functional Component, and state&props ์ ๊ทผ ๊ฐ๋ฅ
effect๋ฅผ ์ฐ๋ ๊ฒฝ์ฐ: requesting React to execute function that is passed as an argument everytime the Component renders.
useEffect
runs after every render of the Component.์ต์์ ์ปดํฌ๋ํธ์์๋ง hook์ ํธ์ถํด์ผํ๋ฉฐ React ํจ์ ๋ด์์ hook์ ํธ์ถํด์ผ ํจ
Conditionally run effects
์ํ ๋์ด์ฌ๋ฆฌ๊ธฐ(lifting state up)
: ํ์ ์ปดํฌ๋ํธ์์์ ํด๋ฆญ ๋ฑ์ ์ด๋ฒคํธ๊ฐ ์์(๋ถ๋ชจ) ์ปดํฌ๋ํธ์ ์ํ๋ฅผ ๋ฐ๊พผ๋ค.
์์ ์ปดํฌ๋ํธ์ ์ํ๋ฅผ ๋ณ๊ฒฝํ ํจ์ ์์ฒด๋ฅผ (๋ง์น ์ฝ๋ฐฑ์ฒ๋ผ) handler๋ก ํ์ props๋ก ์ ๋ฌ, ์ด ํจ์๋ฅผ ํ์ ์ปดํฌ๋ํธ๊ฐ ์คํํ๋ค.
์ฝ๋ฉํ ์คํธ๋ฌธ์ - ์ด์งํ์(Binary Search) *์ฌ๊ท๋ก๋ ๊ฐ๋ฅ(๊ตฌํํด๋ณด๊ธฐ)
big O ์๊ฐ๋ณต์ก๋ nomad coder