Event-driven updates
Trigger a state transition from an event handler.
React 19+ · Type Alias
Dispatch is the function returned by useReducer for requesting a state update. Pass it one action; React gives that action and the current state to the reducer, then re-renders with the reducer's result.
React's official reference documents dispatch as the function returned by useReducer. It accepts one action, which React passes with the current state to the reducer; the reducer returns the next state, and React then re-renders with it.
dispatch(action)| Name | Type | Description |
|---|---|---|
action | any | The action performed by the user; it may be a value of any type. |
No return value.
import { useReducer } from 'react';
type Action = { type: 'increment' } | { type: 'reset' };
function reducer(state: number, action: Action) {
switch (action.type) {
case 'increment': return state + 1;
case 'reset': return 0;
}
}
export default function Counter() {
const [count, dispatch] = useReducer(reducer, 0);
return (
<button onClick={() => dispatch({ type: 'increment' })}>
Count: {count}
</button>
);
}The reducer's dispatch function accepts an action and schedules the next state update.
Trigger a state transition from an event handler.
Send structured commands to a reducer.
Expose state updates through context without prop drilling.
useReducerreducerstateaction