-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducers.ts
36 lines (31 loc) · 859 Bytes
/
reducers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { combineReducers } from 'redux';
import { CREATE_USER, GET_USERS, CREATE_COURSE, GET_COURSES /* import other action types... */ } from './types';
// Define your individual reducers
const usersReducer = (state = [], action) => {
switch (action.type) {
case CREATE_USER:
return [...state, action.payload];
case GET_USERS:
return action.payload;
default:
return state;
}
};
const coursesReducer = (state = [], action) => {
switch (action.type) {
case CREATE_COURSE:
return [...state, action.payload];
case GET_COURSES:
return action.payload;
default:
return state;
}
};
// Other reducers...
// Combine reducers to create the root reducer
const rootReducer = combineReducers({
users: usersReducer,
courses: coursesReducer,
// Other reducers...
});
export default rootReducer;