πΒ Reference
πΒ Chapter
reducer
λ νμ¬ μνμ μ‘μ
κ°μ²΄λ₯Ό νλΌλ―Έν°λ‘ λ°μμμ μλ‘μ΄ μνλ₯Ό λ°νν΄μ£Όλ ν¨μμ΄λ€.reducer
μμ λ°ννλ μνλ 곧 μ»΄ν¬λνΈκ° μ§λ μλ‘μ΄ μνκ° λλ€.const [state, dispatch] = useReducer(reducer, initialArg, init?)
const [<μν κ°μ²΄>, <dispatch ν¨μ>] = useReducer(<reducer ν¨μ>, <μ΄κΈ° μν>, <μ΄κΈ° ν¨μ>)
reducer
ν¨μλ νμ¬ μν(state
) κ°μ²΄μ νλ(action
) κ°μ²΄λ₯Ό μΈμλ‘ λ°μμ μλ‘μ΄ μν(state
) κ°μ²΄λ₯Ό λ°ννλ ν¨μμ΄λ€.dispatch
ν¨μλ component λ΄μμ μν λ³κ²½μ μΌμΌν€κΈ° μν΄μ μ¬μ©λλλ° μΈμλ‘ reducer
ν¨μμ λκΈΈ νλ(action
) κ°μ²΄λ₯Ό λ°λλ€.action
) κ°μ²΄λ κ΄νμ μΌλ‘ μ΄λ€ λΆλ₯μ νλ μΈμ§λ₯Ό λνλ΄λ type μμ±κ³Ό ν΄λΉ νλκ³Ό κ΄λ ¨λ λ°μ΄ν°λ₯Ό λ΄κ³ μλ€.dispatch
ν¨μμ νλ(action
)μ λμ§λ©΄, reducer
ν¨μκ° μ΄ νλ(action
)μ λ°λΌμ μν(state
)λ₯Ό λ³κ²½ν΄μ€λ€.useReducer
Β λ₯Ό μ°κ³ μ΄λ¨ λΒ useState
Β λ₯Ό μ¨μΌ ν κΉ? μΌλ¨, μ¬κΈ°μ μμ΄μλ μ ν΄μ§ λ΅μ μλ€.useState
Β λ‘ κ΄λ¦¬νλκ² νΈν κ²μ΄λ€.