Ollie Block Academy

Data Handling in Blocks

Changing Data in the Store

The useDispatch hook provides action creators for modifying store data, but must be called at the component’s top level, not inside event handlers. Extract action creators into variables for use in click handlers.

Always tie actions to user interactions rather than component renders to avoid unintended side effects. React’s re-rendering behavior could cause actions to fire multiple times without proper event handling.

Use callback functions in onClick handlers rather than direct function calls to ensure actions execute only when users interact with interface elements, not during component initialization or re-renders.

Back to: Ollie Block Academy > Data Handling in Blocks