JS Built-ins
redux-legacyaction-creatorbeginner

Action Creator with Payload

πŸ“– Usage Example
function 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 Creator with Payload

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 }.

πŸ’‘ Hints (2)
  • β€’ The `payload` key is a Redux community convention (Flux Standard Action).
  • β€’ The payload can be any value: a string, number, object, or array.