forked from wednesday-solutions/react-graphql-ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.ts
35 lines (31 loc) · 873 Bytes
/
reducer.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
import { createSlice } from '@reduxjs/toolkit';
import get from 'lodash-es/get';
import { prepare } from '@app/utils';
export const initialState = {
loading: false,
launchData: {},
launchListError: null
};
const homeSlice = createSlice({
name: 'home',
initialState,
reducers: {
requestGetLaunchList: {
reducer: (state) => {
state.loading = true;
},
prepare
},
successGetLaunchList(state, action) {
state.launchListError = null;
state.launchData = action.payload;
state.loading = false;
},
failureGetLaunchList(state, action) {
state.launchListError = get(action.payload, 'message', 'something_went_wrong');
state.loading = false;
}
}
});
export const { requestGetLaunchList, successGetLaunchList, failureGetLaunchList } = homeSlice.actions;
export default homeSlice.reducer;