https://ko.react.dev/reference/react/useReducer#usereducer
useReducer
is a React Hook that lets you add a reducer to your component.
useReducer(reducer, initialArg, init?)
reducer
initialArg
:
init
argument.init
initialArg
.init(initialArg)
.useReducer
returns an array with exactly two values:
The current state.
init(initialArg)
or initialArg
(if there’s no init
).dispatch
function
useReducer
is a Hook, so you can only call it at the top level of your component or your own Hooks.dispatch
functionThe dispatch
function returned by useReducer
lets you update the state to a different value and trigger a re-render. You need to pass the action as the only argument to the dispatch
function:
dispatch
function only updates the state variable for the next render.
dispatch
function, you will still get the old value that was on the screen before your call.