- Redux ๋?
โ action์ ์ฌ์ฉํ์ฌ ์ ํ๋ฆฌ์ผ์ด์
์ํ๋ฅผ ๊ด๋ฆฌํ๊ณ ์
๋ฐ์ดํธํ๊ธฐ ์ํ ํจํด ๋ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- ์ฌ์ฉ ์์ ๋ฐ ์ค๋ช
//๋ฆฌ๋์ : state ๋ณต์ฌ๋ณธ์ ๊ฐ ์ก์ ์ ๋ฐ๋ผ ์กฐ์ํด์ ์๋ก์ด state ๋ฐํ //cf) setState: ํ์ฌ state๋ฅผ ๋ณ๊ฒฝ, getState: ํ์ฌ state๋ฅผ ๋ฐํ const reducer = (state=[], action) => { switch(action.type) { case "ADD_TODO": //์ํ๋ฅผ ์ด๋ป๊ฒ ์กฐ์ํ ๊น๋ฅผ ์ ์ return [...state, action.text] //์ ์ํ๋ฅผ ๋ฐํ => store์ ์ํ๊ฐ ์ด๊ฑธ๋ก ๋ฐ๋ default: return state } } const store = createStore(reducer, initialState) //์ด์ ์คํ ์ด๋ set/getState๋ฅผ ๊ฐ์ง store.dispatch({ type: "ADD_TODO", text: "๊ณผ์ ํ๊ธฐ" }) // ์ํ๋ฅผ setStateํ๋ ๊ฒ /* const increment = () => { //์ผ๋ฐ์ ์ผ๋ก ์ก์ ์์ฑ์ ์ฌ์ฉ return { type: 'counter/increment' } } store.dispatch(increment()) */ store.getState() // ํ์ฌ ์ํ const handleChange() { } store.subscribe(handleChange) //์ก์ ์ด dispatch๋ ๋๋ง๋ค ํด๋น ๋ฆฌ์ค๋๊ฐ ์คํ๋จ