Last active
January 25, 2017 10:07
-
-
Save jyotendra/0a9d97308cce15e7008d0e0fdbb38753 to your computer and use it in GitHub Desktop.
React-redux action creator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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