suhyang-lee / bugfix

๋‚ด๊ฐ€ ๊ฒฝํ—˜ํ•œ ๋ฌธ์ œ๋“ค
0 stars 0 forks source link

[react-native] Invalid hook call. Hooks can only be called inside of the body of a function component. #1

Open suhyang-lee opened 3 years ago

suhyang-lee commented 3 years ago

๐Ÿš€ Error Message

Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app See for tips about how to debug and fix this problem.

๐Ÿ ๋ฌธ์ œ์ •์˜ : ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฌธ์„œ๋ฅผ ๋ณด๊ณ  ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.
๊ฑฐ๊ธฐ์„œ ์‚ฌ์šฉํ•˜๋Š”๋Œ€๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ปดํฌ๋„ŒํŠธ ํ˜•ํƒœ๊ฐ€ ์•„๋‹ˆ๋ผ import ํ•ด์„œ ๊ทธ๋Œ€๋กœ ๋„ฃ์—ˆ๋Š”๋ฐ ๋ฌธ์ œ ๋ฐœ์ƒ

ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

  1. ์—๋Ÿฌ๊ฐ€ ๋‚˜๋Š” ํฌ์ธํŠธ์—์„œ ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š” hooks์„ ํ•˜๋‚˜ํ•˜๋‚˜ ์ œ๊ฑฐํ•˜๋ฉด์„œ ํ๋ฆ„์„ ๋”ฐ๋ผ๊ฐ„๋‹ค.
  2. ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒ๋ถ€๋ถ„์„ ์‚ดํŽด๋ณธ๋‹ค.
  3. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ปดํฌ๋„ŒํŠธ ํ˜•ํƒœ๋ฅผ ์ž˜ ๋”ฐ๋ฅด๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.
  4. props๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋„˜๊ธด๋‹ค๋ฉด ์ด ๋ถ€๋ถ„์„ ์œ ์‹ฌํžˆ ์‚ดํŽด๋ณด๊ณ  ์ปดํฌ๋„ŒํŠธ ํ˜•ํƒœ๋กœ ๋ฐ”๊ฟ”๋ณธ๋‹ค
    
    import lib from '~~'

// ๐Ÿ˜ซ

// ๐Ÿ˜Š }/> ```
suhyang-lee commented 3 years ago

์ฐธ๊ณ ๋กœ redux๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์—” ๋ฌธ์ œ๊ฐ€ ์—†์—ˆ๋Š”๋ฐ redux๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋Š” ๊ฒƒ์„ ๋ณด์•„, ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ redux๊ฐ€ ํ•ฉ์ด ๋งž์ง€ ์•Š์•˜๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ์–ด์จŒ๋“  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ function ํ˜•ํƒœ์˜ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋„˜๊ธธ๋•Œ, ๊ทธ ๋‚ด๋ถ€์—์„œ hooks ๋ฐ redux๋ฅผ ์‚ฌ์šฉํ•  ์ผ์ด ์žˆ๋‹ค๋ฉด ์• ์ดˆ๋ถ€ํ„ฐ ์ปดํฌ๋„ŒํŠธ ํ˜•ํƒœ๋กœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— import ํ•ด์ฃผ๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค.