이준호

[REFACTOR] redux-thunk 미들웨어 추가로 리팩토링 + api 모듈화 작업

import axios from 'axios';
const getQuestion = async () =>{
const res = axios.get("getquestions");
return res;
}
export default getQuestion;
\ No newline at end of file
import axios from 'axios';
const getResult = async (answer) => {
const res = await axios.post("submit",answer);
return res;
}
export default getResult;
\ No newline at end of file
import getResultApi from '../../api/getResult';
// action
const GET_RESULT = 'GET_RESULT';
const GET_RESULT_SUCCESS = 'GET_RESULT_SUCCESS';
......@@ -14,6 +16,18 @@ const initialState = {
error: null
}
export function getResultThunk(answer){
return async (dispatch) => {
dispatch(getResult());
try{
const { data } = await getResultApi(answer);
dispatch(getResultSuccess(data));
}catch(err){
dispatch(getResultError());
}
}
}
function result(
state = initialState,
action
......
import getQuestionApi from '../../api/getQuestion';
// action
const GET_SURVEY = 'GET_SURVEY';
const GET_SURVEY_SUCCESS = 'GET_SURVEY_SUCCESS';
......@@ -14,6 +16,18 @@ const initialState = {
error: null
}
export function getQuestionThunk(){
return async (dispatch) => {
dispatch(getSurvey());
try{
const { data } = await getQuestionApi();
dispatch(getSurveySuccess(data));
}catch(err){
dispatch(getSurveyError());
}
}
}
function survey(
state = initialState,
action
......