action-creatorbeginnerfunction increment() {
return { type: 'INCREMENT' }
}
// Usage:
store.dispatch(increment())Action creators centralise action construction, reducing typo-prone string duplication across the codebase.
An action creator is a function that returns an action object. This keeps action construction consistent and centralised:
function increment() {
return { type: 'INCREMENT' }
}
Calling increment() always produces the same action shape, making it easy to test and refactor.
Challenge: Implement increment() that returns the action object { type: 'INCREMENT' }.