Skip to content

Instantly share code, notes, and snippets.

@jyotendra
Last active January 25, 2017 10:07
Show Gist options
  • Save jyotendra/0a9d97308cce15e7008d0e0fdbb38753 to your computer and use it in GitHub Desktop.
Save jyotendra/0a9d97308cce15e7008d0e0fdbb38753 to your computer and use it in GitHub Desktop.
React-redux action creator
// Example 1 with no payload
export function incrementCounter(){
return {type:"INCREMENT_COUNTER"};
}
/*
The action is only the object that is being return
that is: {type:"INCREMENT_COUNTER"}
Rest of the function is called Action creator - which creates the action
*/
// Example 2: action with addistional data (payload)
export function incrementCounterByIndex(index){
return {type:"INCREMENT_COUNTER", payload:{index}};
}
/*
In this example we are transferring a payload object, with
a property of index.
Remember we are using ES6 convention becuase of which we need not
to write as index: index , LHS=RHS
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment