생활
리액트에서 DB 값을 어떻게 가져올까요?
CommentLis.js
CommentListContainer.js
lib/api/comment.js
iimport client from './client'; export const write = ({ body }) => client.post('/api/comment/write', { body }); export const listComments = ({ body, id }) => { // const queryString = qs.stringify({ client.post('/api/comment/listComments', { body, id , }); };createRequestSage.js
import { call, put } from 'redux-saga/effects'; import { startLoading, finishLoading } from '../modules/loading'; export const createRequestActionTypes = type => { const SUCCESS = `${type}_SUCCESS`; const FAILURE = `${type}_FAILURE`; return [type, SUCCESS, FAILURE]; }; export default function createRequestSaga(type, request) { const SUCCESS = `${type}_SUCCESS`; const FAILURE = `${type}_FAILURE`; return function*(action) { yield put(startLoading(type)); // 로딩 시작 try { const response = yield call(request, action.payload); yield put({ type: SUCCESS, payload: response.data }); } catch (e) { yield put({ type: FAILURE, payload: e, error: true }); } yield put(finishLoading(type)); // 로딩 끝 }; }현재 포스트맨으로 서버에 요청했을땐 JSON형식으로 잘가져와지는데
VIEW에서 댓글 리스트를 뿌리질 못하네요.. 제가 봤을때는 컨테이너에 문제가 있는거같은데
뭐가 문제인지 모르겠습니다 ..
1개의 답변이 있어요!
일단, client.post(댓글API주소)가 맞나요? client.get이 아닌가요? 보통 가져올 때는 get을 많이 하기에 이 부분이 의심됩니다. 그리고 redux-devtools는 설치하셨나요? LISTCOMMNTS_SUCCESS가 실행되고 있는지 아닌지에 따라 에러 찾는 방법이 많이 달라질 것 같습니다.