Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. // scoreboard-reducer.js
  2. const INITIAL_STATE = {
  3. home: 0,
  4. away: 0,
  5. }
  6.  
  7. export const scoreboardReducer = (state = INITIAL_STATE, action) {
  8. switch (action.type) {
  9. case 'INCREMENT_SCORE':
  10. const scoringSide = action.payload.team;
  11. return {...state, [scoringSide]: state.[scoringSide] + 1 };
  12. default:
  13. return state;
  14. }
  15. }
  16.  
  17. // Some container component
  18. export class Game extends React.Component {
  19. ...
  20. onGoalScored(scoringTeam) {
  21. this.props.dispatch({type: 'INCREMENT_SCORE', team: scoringTeam}
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement