daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top