π Reference
π Index
function reducer(state, action) {
// μν μ
λ°μ΄νΈ λ‘μ§
return alteredState;
}
useReducer
Β λ₯Ό μ¬μ©ν λ μμ±νλ 리λμμ λκ°μ ννλ₯Ό κ°μ§κ³ μλ€.function counter(state, action) {
switch (action.type) {
case 'INCREASE':
return state + 1;
case 'DECREASE':
return state - 1;
default:
return state;
}
}
useReducer
Β μμ μΌλ°μ μΌλ‘Β default:
Β λΆλΆμΒ throw new Error('Unhandled Action')
κ³Ό κ°μ΄ μλ¬λ₯Ό λ°μμν€λλ‘ μ²λ¦¬νλ κ² μΌλ°μ μΈ λ°λ©΄ 리λμ€μ 리λμμμλ κΈ°μ‘΄Β state
λ₯Ό κ·Έλλ‘ λ°ννλλ‘ μμ±ν΄μΌ νλ€.Root Reducer
)λ₯Ό λ§λ€ μ μλ€. (λ£¨νΈ λ¦¬λμ μμ μμ 리λμλ€μ μλΈ λ¦¬λμλΌκ³ λΆλ₯Έλ€.)store
λ μ‘μ
μ΄ μ΄λ€ μν λ³νλ₯Ό λ§λλμ§ μ νμκ° μμ λ reducer
μκ² λ¬»λλ€.root reducer
λ μ ν리μΌμ΄μ
μν κ°μ²΄μ ν€(key
)λ₯Ό κΈ°μ€ μΌμ μνλ₯Ό μ‘°κ°μ‘°κ° λλλ€.reducer
μκ² λ겨μ€λ€.reducer
λ λ§μΉ μλ₯ 볡μ¬μ μ§λμΉκ² μ΄μ±μ μΈ μ¬λ¬΄μ€ μ§μλ€κ³Ό κ°λ€.