[React] 🚨 Error: Maximum update depth exceeded. 🚨 useEffect Error 🚨

CreatyJohnΒ·2024λ…„ 8μ›” 19일

ERROR

λͺ©λ‘ 보기
4/4
post-thumbnail

🚨 Error Log

Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.




🧨 Error Found

λ¬Έμ œλŠ” useEffect λ₯Ό μ‚¬μš©ν•˜λŠ” κ³Όμ •μ—μ„œ λ°œκ²¬λ˜μ—ˆλ‹€
λ¬Έμ œμ μ„ λ°œκ²¬ν•΄λ³΄μž

  useEffect (() => {
  	// 힌트 : useEffect 의 loop μ„±μ§ˆ νŒŒμ•…ν•˜κΈ°
    /* λ‚΄μš© */
  })

자, λ¬Έμ œλŠ” λ°”λ‘œ

πŸ“ Error Solute

useEffect 의 호좜 μ‹œμ μ΄λ‹€
useEffect 은 λ³„λ„μ˜ 호좜 μ‹œμ μ„ μ„ μ–Έν•΄μ£Όμ§€ μ•ŠλŠ”λ‹€λ©΄ λ¬΄ν•œ 루프λ₯Ό 돌게 λœλ‹€

React-useEffect λŠ” μΈν„°λ²Œ ν˜Ήμ€ μ™ΈλΆ€μ™€μ˜ μƒν˜Έ μž‘μš©μ˜ ν•„μš”λ‘œ μ œκ³΅ν•˜λŠ” μƒνƒœκ΄€λ¦¬ Function μ΄λ―€λ‘œ ν˜ΈμΆœν•˜λŠ” μˆœκ°„μ΄ μ€‘μš”ν•˜λ‹€

Solute Code
  useEffect (() => {
    /* λ‚΄μš© */
  }, [])

/* [] κ°€ λΉ„λ©΄ μ»΄ν¬λ„ŒνŠΈ λ Œλ”λ§ μ‹œμ—λ§Œ 호좜
     ||(or) μ˜μ‘΄μ„± 배열을 λ„£μ–΄, 호좜 μ‹œμ μ„ ꡬ체화 μ‹œν‚€λŠ” 것이 κ°€λŠ₯ */
μ΄μ™Έμ˜ μ°Έμ‘°λŠ” κ΅¬κΈ€λ§μœΌλ‘œ~

πŸ•΅οΈβ€ Error is Best Teacher
λ¦¬μ•‘νŠΈλ₯Ό μ‹œμž‘ν•œμ§€ μ–΄λŠλ§, 6κ°œμ›”? μ΄μ§€λ§Œ
아직 λͺ¨λ“  κ°œλ…μ— 100% λ„λ‹¬ν•˜μ§€ λͺ»ν•œ μƒνƒœλΌκ³  μƒκ°ν•œλ‹€

(κ°κ΄€μ μœΌλ‘œ 아직 50% 만 μ΄ν•΄ν•œ 것 κ°™λ‹€ πŸ˜…)
profile
μœ μ—°ν•˜κ²Œ κ°œλ°œν•˜λŠ” ν”„λ‘ νŠΈμ—”λ“œ & AOS 개발자

0개의 λŒ“κΈ€