Last active
March 18, 2019 19:06
-
-
Save alaboudi/14b1459197b0a08abc6d4a224049bcaa to your computer and use it in GitHub Desktop.
This file contains 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
// scoreboard-reducer.js | |
const INITIAL_STATE = { | |
home: 0, | |
away: 0, | |
} | |
export const scoreboardReducer = (state = INITIAL_STATE, action) { | |
switch (action.type) { | |
case 'INCREMENT_SCORE': | |
const scoringSide = action.payload.team; | |
return {...state, [scoringSide]: state.[scoringSide] + 1 }; | |
default: | |
return state; | |
} | |
} | |
// Some container component | |
export class Game extends React.Component { | |
... | |
onGoalScored(scoringTeam) { | |
this.props.dispatch({type: 'INCREMENT_SCORE', team: scoringTeam} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment