๐ฑredux ์ฐ๋ ์ด์
- ๋ชจ๋ ์ปดํฌ๋ํธ๊ฐ props์์ด state ์ง์ ์ฌ์ฉ ๊ฐ๋ฅ
- state ์๋ฌ ์ถ์ ์ฉ์ดํจ (state๋ฐ์ดํฐ์ ์์ ๋ฐฉ๋ฒ: reducer)
๋ฐ์ดํฐ ์์ ํ๊ธฐ
1) reducer๋ก ์์ ํ๋ ๋ฐฉ๋ฒ ๋ง๋ค๊ธฐ
2) dispatch()๋ก ์์ ํ๊ธฐ
=> state ๋ฐ์ดํฐ ๊ด๋ฆฌ ๊ธฐ๋ฅ(์ํ๊ด๋ฆฌ ์ฉ์ด)
๐ฑreducer
- state๊ฐ ์ฌ๋ฌ ๊ฐ ํ์ํ ๋๋ reducer๋ฅผ ๋ ๋ง๋ค๊ธฐ
- reducer ์์๋ state ์ด๊ธฐ๊ฐ + ์์ ํ๋ ๋ฒ ๋ฃ๊ธฐ
- reducer ํฉ์น ๋? combineReducers({})
- reducer์ ์ก์
ํ๋ผ๋ฏธํฐ = dispatch()ํ ๋ ๋ณด๋ธ object
๐ฑredux ์
ํ
- store์ state์ ์ฅ ํ, < Provider > ๋ก ์ํ๋ ๊ณณ ๊ฐ์ธ๊ธฐ
- redux store๋ฐ์ดํฐ ์ฌ์ฉ: props๋ก ๋ฐ๊ฟ์ฃผ๋ ํจ์ ์ฐ๊ธฐ
- dispatchํ ๋ ๋ฐ์ดํฐ ํจ๊ป ์ ์กํด์ฃผ๊ธฐ
- ์ ์กํ ๋ฐ์ดํฐ ์ฐ๋ ค๋ฉด? action.payload
๐ฑ์ปดํฌ๋ํธ์์ store์ ์๋ state ์ฐ๋ ๋ฐฉ๋ฒ
- ์ฒซ์งธ, function ๋ง๋ค๊ธฐ
- ๋์งธ, export default connect()()
- ์
์งธ, store๋ฐ์ดํฐ๋ฅผ props๋ก ๋ฑ๋กํ๊ธฐ