Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement