๐Ÿคนโ€โ™€๏ธ ๋ฆฌ์•กํŠธ์˜ ์ƒํƒœ ๊ด€๋ฆฌ: useState, ContextAPI, Redux

์ •์€๊ฒฝยท2020๋…„ 9์›” 9์ผ
0

๐Ÿ‘ธ Front-End Queen

๋ชฉ๋ก ๋ณด๊ธฐ
54/271

์–ด๋–ค ๋ณ€์ˆ˜์˜ ์ƒํƒœ๊ฐ€ ์žˆ๋‹ค
์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•ด์•ผํ•œ๋‹ค.
์™œ๋ƒํ•˜๋ฉด ์ด ์ƒํƒœ์—์„œ ๋”ฐ๋ผ์„œ ์ปดํฌ๋„ŒํŠธ์—์„œ ๋ Œ๋”๋˜๋Š” ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฐ”๋€Œ์–ด์•ผํ•œ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๋ณ€์ˆ˜์™€ ๋ณ€์ˆ˜๋“ค์˜ ์„œ๋กœ์˜ ์ƒํƒœ์— ์˜ํ–ฅ์„ ์ค€๋‹ค.

redux vs. contextAPI

  1. ๋ฏธ๋“ค์›จ์–ด
  2. ์œ ์šฉํ•œ ํ•จ์ˆ˜์™€ hooks
  3. ํ•˜๋‚˜์˜ ์ปค๋‹ค๋ž€ ์ƒํƒœ

๋ฐฉ๋ฒ•#1. useState ์‚ฌ์šฉํ•˜๊ธฐ

์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฉ๋ฒ•: useState
useState๋ฅผ ์ตœ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ์—์„œ ์‚ฌ์šฉํ•ด์„œ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ 
ํ•˜์œ„ ์ž์‹๋“ค์—๊ฒŒ ์ƒํƒœ๋ฅผ props๋กœ ์ „๋‹ฌํ•˜๋Š” ํ˜•ํƒœ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Œ

๋ฐฉ๋ฒ•#2. ContextAPI

์ƒํƒœ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ContextProvider์— ์ž‘์„ฑํ•˜๊ณ 
์ด ์ƒํƒœ์ •๋ณด๋ฅผ ํ•„์š”ํ•œ ์ปดํฌ๋„ŒํŠธ๋“ค์€ ๊ทธ๋ƒฅ ContextProvider๋ฅผ importํ•˜๋ฉด ๊ทธ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Œ

ํ—!! ๊ณ„์† ๋ณ€๊ฒฝ๋˜๋Š” state๊ด€๋ฆฌ๋กœ contextAPI ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๋ˆˆ๋ฐ..!!

๊ฐ ๋ฐฉ๋ฒ•๋“ค์€ ์žฅ๋‹จ์ ์ด ์žˆ๋‹ค?!

Reference

profile
#์˜์‹์˜ํ๋ฆ„ #์ˆœ๊ฐ„์ˆœ๊ฐ„ #์ƒ๊ฐ์˜์Šค๋ƒ…์ƒท

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