Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Created October 7, 2017 18:50
Show Gist options
  • Save vzaidman/f927ba1c5905c4a0993d3db0a6723b93 to your computer and use it in GitHub Desktop.
Save vzaidman/f927ba1c5905c4a0993d3db0a6723b93 to your computer and use it in GitHub Desktop.
Example
// The action creator increaseBy is imported
// instead of the action's name from consts.js
import { increaseBy, decreaseBy } from './actions'
const deafaultCount = 100
export default countReducer = (count = deafaultCount, { payload, type }) => {
switch(type){
// an action creator is used inside the reducer to get it's type
case increaseBy.TYPE: {
return count + payload
}
// another action creator is used inside the reducer to get it's type
case decreaseBy.TYPE: {
return count - payload
}
default: {
return count
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment