useSelector

laluniaxยท2023๋…„ 11์›” 21์ผ
2

REACT

๋ชฉ๋ก ๋ณด๊ธฐ
13/20

์šฐ๋ฆฌ๊ฐ€ ์ƒ์„ฑํ•œ ๋ชจ๋“ˆ์„ ์Šคํ† ์–ด์— ์ž˜ ์—ฐ๊ฒฐํ–ˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๋ญ˜๊นŒ?
useSelector๋ผ๋Š” ํ›…์„ ์‚ฌ์šฉํ•ด์„œ = ์ €์žฅ์†Œ๋ฅผ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋‹ค.

๐Ÿ“– useSelector

์‚ฌ์šฉ๋ฐฉ๋ฒ•
1. store์—์„œ ๊บผ๋‚ธ ๊ฐ’์„ ํ• ๋‹น ํ•  ๋ณ€์ˆ˜๋ฅผ ์„ ์–ธ

const number = 

2. useSelector()๋ฅผ ๋ณ€์ˆ˜์— ํ• ๋‹น

const number = useSelector() 
  1. useSelector์˜ ์ธ์ž์— ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๋ฅผ ๋„ฃ๋Š”๋‹ค.
const number = useSelector( ()=>{} )
  1. ํ™”์‚ดํ‘œ ํ•จ์ˆ˜์˜ ์ธ์ž์—์„œ ๊ฐ’์„ ๊บผ๋‚ด return
    ๋ชจ๋ฅด๊ฒ ๊ฑฐ๋‚˜ ๊ถ๊ธˆํ•˜๋ฉด ๋ฌด์กฐ๊ฑด ์ฝ˜์†”๋กœ ์ฐ์–ด๋ณด๋Š” ๊ฑธ ์Šต๊ด€ํ™” ํ•˜์ž ~!
const number = useSelector((state) => {
  					 ์—ฌ๊ธฐ์„œ state๋Š” ์ค‘์•™ ์ €์žฅ์†Œ ์•ˆ์— ์žˆ๋Š” ์ „์ฒด state๋ฅผ ๋งํ•œ๋‹ค !! 
	console.log(state)
	return state
});

์ฝœ๋ฐฑํ•จ์ˆ˜ ์•ˆ์—์„œ ์ธ์ž๊ฐ’์— ์ž‘๋ช…ํ•˜๊ณ  ๊ทธ ๋‚ด๋ถ€์— ์‹คํ–‰์‹œํ‚จ๋‹ค.


profile
grow constantly

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