Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/teratail q267220 #1

Closed
Prev Previous commit
Next Next commit
Replace state property "response" to "arrayExample"
  • Loading branch information
jun68ykt committed Jun 4, 2020
commit 8184fbed4a1d3646872cdbb9e69ff23ac40a7efb
26 changes: 11 additions & 15 deletions src/redux/main/reducer.js
Expand Up @@ -8,24 +8,23 @@ import {
} from './action';

const initialState = {
isFetching: true,
isFetching: false,
isError: false,
response: {},
arrayExample: [],
count: {},
error: null
};

const mainState = (state = initialState, action) => {
switch (action.type) {
// API
case REQUEST_FETCH:
return {
...state,
};
return { ...state, isFetching: true };
// API成功
case SUCCEED_FETCH:
return {
...state,
response: action.response,
arrayExample: action.response.arrayExample,
isError: false,
isFetching: false,
};
Expand All @@ -35,29 +34,26 @@ import {
...state,
isFetching: false,
isError: true,
response: action.error,
error: action.error,
};
// 再レンダー
case REQUEST_REFETCH:
console.log('refetch')
return {
...state,
};
console.log('refetch')
return { ...state, isFetching: true };
// 再レンダー成功
case SUCCEED_REFETCH:
console.log(state.response);
return {
...state,
response: [...state.response, action.results],
// response: state.response.concat([action.results]),
arrayExample: [...state.arrayExample, ...action.results.arrayExample],
isFetching: false,
};
// 再レンダーエラー
case FAILED_REFETCH:
return {
...state,
isFetching: false,
isError: true,
response: action.reError,
error: action.reError,
};
default:
return state;
Expand Down