action-creatorbeginnerfunction addItem(item) {
return { type: 'ADD_ITEM', payload: item }
}
store.dispatch(addItem('apple'))
// dispatches β { type: 'ADD_ITEM', payload: 'apple' }Passing the payload as a parameter lets you reuse one action creator for any value instead of hard-coding it.
Action creators become more powerful when they accept arguments and include them in the action's payload:
function addItem(item) {
return { type: 'ADD_ITEM', payload: item }
}
This follows the Flux Standard Action convention: { type, payload }.
Challenge: Implement addItem(item) that returns { type: 'ADD_ITEM', payload: item }.