Too many re-renders...??

ppbyยท2020๋…„ 7์›” 20์ผ
6

ppby.error

๋ชฉ๋ก ๋ณด๊ธฐ
1/2

๐Ÿšจ ์—๋Ÿฌ ์ •๋ฆฌ ๊ธ€ (๋‚˜๋ฆ„๋Œ€๋กœ ์—๋Ÿฌ๊ฐ€ ๋‚œ ์ด์œ ๋ฅผ ์ •๋ฆฌํ–ˆ์ง€๋งŒ ํ‹€๋ฆฐ ๋‚ด์šฉ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค...)

๐Ÿ’ฅ ์ด๊ฑด ๋˜ ๋ฌด์Šจ ์—๋Ÿฌ...?

Too many re-renders. React limits the number of renders to prevent an infinite loop.

๐Ÿ˜ƒ ์˜์–ด ํ•ด์„ (๋ฌผ๋ก  ๊ตฌ๊ธ€ ๋ฒˆ์—ญ)
โ†’ ๋ฆฌ๋ Œ๋”๋ง์ด ๋„ˆ๋ฌด ๋งŽ์Šต๋‹ˆ๋‹ค. React๋Š” ๋ฌดํ•œ ๋ฃจํ”„๋ฅผ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋ Œ๋” ์ˆ˜๋ฅผ ์ œํ•œํ•ฉ๋‹ˆ๋‹ค

  • ๋Œ€์ถฉ ์ด๋Ÿฐ ๋‚ด์šฉ์ด๋‹ค.
    ์ผ๋‹จ, ๋ฌธ์žฅ ๊ทธ๋Œ€๋กœ ๊ตฌ๊ธ€์— ๊ฒ€์ƒ‰ํ•ด ๋ดค๋‹ค. ์—ฌ๋Ÿฌ ๊ฒŒ์‹œ๊ธ€์„ ๋ณด๋‹ค๊ฐ€ ๋น„์Šทํ•œ ํŠน์ง•์„ ๋ฐœ๊ฒฌํ–ˆ๋‹ค.
  • ์ด๋Ÿฐ ์‹์œผ๋กœ props์— ํ•จ์ˆ˜๋ฅผ ๋„ฃ์€ ๊ฒƒ์ด ์•„๋‹ˆ์–ด์„œ ๋ฌดํ•œ๋ฃจํ”„๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.
    (onIncrease , onDecrease ๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ porps๋กœ ๋ฐ›์€ ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰๋ผ์•ผ ํ•จ)

๐Ÿค” ์ˆ˜์ •

  • ๊ฐ„๋‹จํ•˜๊ฒŒ ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋กœ ๋‹ค์‹œ ๋งŒ๋“ค์–ด ์คฌ๋‹ค.
  • โ—๏ธprops๋กœ ์ „๋‹ฌ ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜๋Š” useCallback์œผ๋กœ ๊ฐ์‹ธ ์ฃผ๋Š” ๊ฒƒ์ด ์„ฑ๋Šฅ ์ตœ์ ํ™”์— ๋„์›€๋œ๋‹ค.
profile
(เธ‡ โ€ขฬ€_โ€ขฬ)เธ‡ย 

0๊ฐœ์˜ ๋Œ“๊ธ€