728x90
๋ฆฌ๋์ค ์คํฐ๋์ค handleAction์ ์ฌ์ฉํ๋ ์ค ํด๋น ์์ค์์ ๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํจ
// ๋ฆฌ๋์ค ๋ชจ๋
import { createAction, handleAction } from 'redux-actions'
const INCREASE = 'counter/INCREASE'
const DECREASE = 'counter/DECREASE'
export const increase = createAction(INCREASE)
export const decrease = createAction(DECREASE)
const initialState = 0
const counter = handleAction({
[INCREASE]: state => state + 1,
[DECREASE]: state => state - 1
}, initialState)
export default counter;
defaultState for reducer handling [object Object] should be defined
์ด๋ฌํ ์๋ฌ๊ฐ ๋ํ๋๋ ์ด์ ๋ ์ก์ ์ด 2๊ฐ ์ด์์ด๊ธฐ ๋๋ฌธ.
2๊ฐ ์ด์์ ์ก์ ์ ์ฒ๋ฆฌํ๋ ค๋ฉด handleAction => handleActions๋ก ๋ณ๊ฒฝํ๋ค.
๊ทธ๋ฌ๋ฉด ์๋ฌ๊ฐ ํด๊ฒฐ๋๋ค .
๊ตณ์ด ๊ตณ์ด handleAction์ ์ฌ์ฉํด์ผํ๋ค๋ฉด, ํ๋์ ์ก์ ๋ง ์ค์ ํด ์ฃผ๋ฉด๋๋ค.
// ๋ฆฌ๋์ค ๋ชจ๋
import { createAction, handleAction } from 'redux-actions'
const INCREASE = 'counter/INCREASE'
export const increase = createAction(INCREASE)
const initialState = 0
const counter = handleAction(
INCREASE,
state => state + 1,
initialState
)
export default counter;
๋ณดํต์ ํ๋ก์ ํธ๋ฅผ ๋ณด๋ฉด handleAction์ ๊ฑฐ์ ์ฌ์ฉํ ์ผ์ด ์์๊ฒ ๊ฐ๋ค. ๐คจ
๋ฐ์ํ
'๊ฐ๋ฐ ๐พ > ReactJS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
React์์ ๊ฐ๋ก ์คํฌ๋กค ๊ตฌํํ๊ธฐ (react-horizontal-scrolling-menu) (2) | 2021.06.03 |
---|---|
[React][ํ๊ฒฝ์ธํ ] react-router-dom ์ฌ์ฉํ๊ธฐ (0) | 2021.05.25 |
React Hook ์์ Scroll ์ปจํธ๋กค ํ๊ธฐ! top๋ฒํผ ๊ตฌํ (1) | 2021.02.09 |
๋ชจ๋๊ฐ ์์ฃผ ์ฌ์ฉํ๋ React ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ ๋ฆฌ (0) | 2021.02.06 |
React-datepicker ์ปค์คํ ํ๊ธฐ (2) | 2021.02.02 |