RDP [Container] 2.4 UserLoader

้‡‘็ง€ยท2022๋…„ 6์›” 8์ผ
0

๋งค์ผ ๋ฆฌ์•กํŠธ

๋ชฉ๋ก ๋ณด๊ธฐ
12/15

08/06/2022

  • ์ง€๊ธˆ์˜ currentUserLoader.js๋Š” v restricted to what it's capable of doing.
  • just load 1 user => pass it to children components

๐Ÿ™‚๋ฆฌํŒฉํ„ฐ๋ง 1 ANY USER by thier id

  1. create userLoader.js

  2. copy & paste all the code from CurrentUserLoader to userLoader

  3. MAIN THING TO CHANGE! => url๋กœ request ํ•  ๊ฒƒ์ž„
    by using an api call in server.js

    => line 9 ์˜ axios.get() ์•ˆ์˜ endpoint ๋ฅผ /current-user์—์„œ
    ๋ถ€๋ชจ์ปดํฌ๋„ŒํŠธ์—์„œ passํ•ด์ฃผ๋Š” prop์ถ”๊ฐ€ํ•ด์„œ, insert that in the url

  4. [userId] ๋ฅผ useEffect ๊ฐ์‹œ ๊ฐ’์œผ๋กœ ๋„ฃ๊ธฐ

    DATA ์ƒ๊ธด ๋ชจ์–‘


  5. Add userLoader in App.js

๐Ÿงจ go 1 step further - DRY, refactor IT

  • user id array ๋งŒ๋“ค๊ณ  map ๋Œ๋ฆฌ๊ธฐ!
profile
๊ธฐ๋กํ•˜๊ธฐ

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

๊ด€๋ จ ์ฑ„์šฉ ์ •๋ณด