Calling useDispatch() returns a reference to the exact same dispatch function belonging to the store the app's Provider is wrapping, letting any component trigger a Redux state update by dispatching a plain action object, which the store then routes through the root reducer to compute the new state. Combined with action creator functions, plain functions that construct and return properly-shaped action objects, dispatch(actionCreator(someArgument)) is the standard, idiomatic pattern for triggering Redux updates from event handlers or effects inside components.
1Understanding useDispatch
Calling useDispatch() returns a reference to the exact same dispatch function belonging to the store the app's Provider is wrapping, letting any component trigger a Redux state update by dispatching a plain action object, which the store then routes through the root reducer to compute the new state. Combined with action creator functions, plain functions that construct and return properly-shaped action objects, dispatch(actionCreator(someArgument)) is the standard, idiomatic pattern for triggering Redux updates from event handlers or effects inside components.
Wrap action creation in a plain action-creator function, like addTodo(text), rather than manually constructing the action object with the correct type and payload shape inline at every dispatch call site — it keeps the action's exact shape defined in one place and reduces the chance of typos in the type string.
import { useDispatch } from 'react-redux';
function IncrementButton() {
const dispatch = useDispatch();
return <button onClick={() => dispatch({ type: 'increment' })}>+1</button>;
}2Practical Example
Here is a real-world application of useDispatch showing how it is used in production React code.
import { useDispatch } from 'react-redux';
const addTodo = (text) => ({ type: 'todos/add', payload: { text, done: false } });
function AddTodoForm() {
const dispatch = useDispatch();
const handleAdd = () => dispatch(addTodo('Buy milk'));
return <button onClick={handleAdd}>Add Todo</button>;
}3Best Practices
Follow these guidelines when working with useDispatch:
1. Use action creator functions to construct properly-shaped action objects, then pass their result to dispatch(), rather than writing out the action object shape inline at every call site
2. Call dispatch() from event handlers or effects in response to user interaction or other triggers, letting the reducer decide exactly how that action transforms the state
3. Avoid dispatching an action synchronously and unconditionally inside a component's render body, since dispatch triggers a state update, and doing so during render can create an infinite update loop
Tip: Wrap action creation in a plain action-creator function, like addTodo(text), rather than manually constructing the action object with the correct type and payload shape inline at every dispatch call site — it keeps the action's exact shape defined in one place and reduces the chance of typos in the type string.
import { useDispatch } from 'react-redux';
function IncrementButton() {
const dispatch = useDispatch();
return <button onClick={() => dispatch({ type: 'increment' })}>+1</button>;
}