-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-reducer.ts
More file actions
41 lines (37 loc) · 771 Bytes
/
api-reducer.ts
File metadata and controls
41 lines (37 loc) · 771 Bytes
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
37
38
39
40
41
/* eslint-disable @typescript-eslint/no-unused-vars */
export const INITIAL_STATE: InfoApi = {
isLoading: false,
isError: false,
data: null,
errorMsg: '',
};
export enum ACTION_TYPE {
FETCH_START = 'START',
FETCH_SUCCESS = 'SUCCESS',
FETCH_FAILED = 'FAILED',
}
export const apiReducer = (state: InfoApi, action: ActionReducer) => {
switch (action.type) {
case ACTION_TYPE.FETCH_START:
return {
...state,
isLoading: true,
isError: false,
};
case ACTION_TYPE.FETCH_SUCCESS:
return {
isLoading: false,
isError: false,
data: action.payload,
};
case ACTION_TYPE.FETCH_FAILED:
return {
...state,
isLoading: false,
isError: true,
errorMsg: action.errorMsg,
};
default:
return INITIAL_STATE;
}
};