10 examples of 'reduce in react' in JavaScript

Every line of 'reduce in react' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
22export default function reduce(state = initialState, action) {
23 switch (action.type) {
24 case SPOTIFY_TOKENS:
25 const {accessToken, refreshToken} = action;
26 return Object.assign({}, state, {accessToken, refreshToken});
27 case SPOTIFY_ME:
28 return Object.assign({}, state, {
29 user: Object.assign({}, state.user, action.data)});
30 case DEVICES:
31 const {devices} = action;
32 return Object.assign({}, state, {devices});
33 default:
34 return state;
35 }
36}
14export default function reduce(state = initialState, action) {
15 switch (action.type) {
16 case ACCOUNT_REQUEST: {
17 return Object.assign({}, state, {
18 isLoading: true
19 });
20 }
21 case ACCOUNT_RECEIVE: {
22 return Object.assign({}, state, {
23 isLoading: false,
24 ...action.account
25 });
26 }
27 case ACCOUNT_MUTATE: {
28 return Object.assign({}, state, {
29 ...action.account
30 });
31 }
32 default:
33 return state;
34 }
35}
20export default function reduce(state = initialState, action = {}) {
21 const { type, payload, meta } = action;
22 switch (type) {
23 case LOAD_HISTORY_COMPLETE:
24 return payload.map(normalize);
25 case ADVANCE: {
26 const mostRecent = state[0];
27 // If the currently playing track is already in the history, remove it--
28 // it'll be added back on the next advance, and will be handled by the
29 // roomHistorySelector in the mean time.
30 if (mostRecent && payload && mostRecent._id === payload.historyID) {
31 return state.slice(1);
32 }
33 if (!meta || !meta.previous) {
34 return state;
35 }
36 return [normalize(meta.previous), ...state];
37 }
38 default:
39 return state;
40 }
41}
9function reduce(state = initialState, action = {}) {
10 const { type, payload } = action;
11 switch (type) {
12 case 'setUsers':
13 return indexBy(payload.users, '_id');
14 case 'join':
15 return {
16 ...state,
17 [payload.user._id]: payload.user
18 };
19 case 'leave':
20 return except(state, payload.userID);
21 default:
22 return state;
23 }
24}
24return function reduce (state, action) {
25 var updates = fn(state, action)
26 return update(state, updates)
27}
5export default function reduce(state = initialState, action = {}) {
6 const { type, payload } = action;
7 switch (type) {
8 case OPEN_OVERLAY:
9 return payload.overlay;
10 case TOGGLE_OVERLAY:
11 return state === payload.overlay ? null : payload.overlay;
12 case CLOSE_OVERLAY:
13 return null;
14 default:
15 return state;
16 }
17}
6function reduce(state = initial, action) {
7 switch(action.type) {
8 case LOAD_USER_COMPLETE:
9
10 return {
11 ...state,
12 [action.user.id]: {
13 ...state[action.user.id],
14 ...action.user
15 }
16 }
17 default:
18 return state
19 }
20}
22reduce(state, action) {
23 if (this.handlers.has(action.type)) {
24 return this.handlers.get(action.type)(state || this.initialState, action)
25 } else {
26 return this.defaultHandler(state || this.initialState, action)
27 }
28}
3function reduceInstancesToState(props) {
4 const style = {}
5 for (const prop of props) {
6 Object.assign(style, prop.setStyle)
7 }
8 return style
9}
28export function reduce(state: State, commit: Commit): State {
29 switch (commit.type) {
30 case 'AddLog':
31 return {
32 ...state,
33 logs: [
34 ...state.logs,
35 {
36 action: commit.action,
37 snapshot: commit.snapshot,
38 }
39 ],
40 selectedLog: typeof state.selectedLog !== 'number' ?
41 state.logs.length :
42 state.selectedLog,
43 selectedSnapshotItem: commit.snapshot[0] || null,
44 };
45 case 'SelectLog':
46 return commit.logIndex === state.selectedLog ? state : {
47 ...state,
48 selectedLog: commit.logIndex,
49 selectedSnapshotItem: state.logs[commit.logIndex].snapshot[0] || null,
50 };
51 case 'SelectSnapshotItem':
52 return {
53 ...state,
54 selectedSnapshotItem: commit.snapshotItem,
55 };
56 default:
57 return state;
58 }
59}

Related snippets