inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Ko Yun Hyuk님의 게시글

Ko Yun Hyuk Ko Yun Hyuk

@sksgur3217

수강평 작성수
1
평균평점
5.0

게시글 38

질문&답변

ADD_POST_TO_ME 질문있습니다.

back/routes/user.js 늦은 시간 죄송하고.. 답변 감사합니다. include 문제였습니다..

좋아요수
0
댓글수
2
조회수
245

질문&답변

새로고침 시 hydrate 상태 초기화 문제 질문 있습니다.

처음에는 request 요청이 가면 success 까지 잘 받아오는데 새로고침을 하면 request만 가고 이후 success에 대한 응답이 없습니다. req.header에 cookie는 잘 담겨 있고 요청에 따라 cookie 변수에도 잘 담겨있는걸 확인했습니다. 그런데 이후 request 만 가고 success에 대한 응답이 없고 null 값입니다. redux-saga에서 요청하고 sucess까지 받아오는데 기다리지를 못하는 것 같습니다. 그런데 코드에는 아무리 봐도 이상이 없습니다... 구글링을 통해 다른 코드를 참고하여 살펴봐도 여전히 문제점을 발견하지 못하고 있습니다ㅠㅠ import { END } from 'redux-saga' ; import { wrapper } from '../store/configureStore' ; import axios from 'axios' ; . . . export const getServerSideProps = wrapper . getServerSideProps (( store ) => async ({ req , res , ... ets }) => { console . log ( 'getServerSideProps req.headers: ' , req . headers ); const cookie = req ? req . headers . cookie : '' ; console . log ( 'cookie: ' , cookie ); axios . defaults . headers . Cookie = '' ; // 서버에서 다른 사람과 cookie가 공유되는 문제를 방지하고자 초기화를 해준다. if ( req && cookie ) { axios . defaults . headers . Cookie = cookie ; // 서버에서 요청일때랑 cookie가 있으면 설정한 cookie를 넣어준다. console . log ( 'axios.defaults.headers.Cookie: ' , axios . defaults . headers . Cookie ); } store . dispatch ({ type : LOAD_MY_INFO_REQUEST , }); store . dispatch ( END ); await store . sagaTask . toPromise (); // reducers/index.js import { combineReducers } from 'redux' ; // 여러 리듀서들을 하나로 합쳐준다. import { HYDRATE } from 'next-redux-wrapper' ; import user from './user' ; import post from './post' ; // HYDRATE가 동작할 때 initStates들이 index user post 자체를 덮어씌울 수 있도록 구조를 작성 const rootReducer = ( state , action ) => { switch ( action . type ) { case HYDRATE : console . log ( 'HYDRATE' , action ); return action . payload ; default : { const combineReducer = combineReducers ({ user , post , }); return combineReducer ( state , action ); } } }; export default rootReducer ; 참고: https://github.com/ko7452/e-Library 제 github 입니다..

좋아요수
0
댓글수
7
조회수
896

질문&답변

새로고침 시 hydrate 상태 초기화 문제 질문 있습니다.

백엔드로 전달이 안되는 문제라면 프론트 서버에서 문제가 있다는 말씀이신데... 구글링을 해봐도 코드에 무슨 문제가 있는지 잘 파악이 되지 않습니다 ㅠ import { END } from 'redux-saga' ; import { wrapper } from '../store/configureStore' ; import axios from 'axios' ; . . . // getServerSideProps: 브라우저는 개입 못함, 순전히 Front Server에서 실해됨 export const getServerSideProps = wrapper . getServerSideProps (( store ) => async ({ req }) => { console . log ( 'getServerSideProps req: ' , req ); const cookie = req ? req . headers . cookie : '' ; axios . defaults . headers . Cookie = '' ; // 서버에서 다른 사람과 cookie가 공유되는 문제를 방지하고자 초기화를 해준다. if ( req && cookie ) { axios . defaults . headers . Cookie = cookie ; // 서버에서 요청일때랑 cookie가 있으면 설정한 cookie를 넣어준다. } store . dispatch ({ type : LOAD_MY_INFO_REQUEST , }); store . dispatch ( END ); await store . sagaTask . toPromise (); }); 아니면 하나의 액션만 실행되고 그 다음으로 넘어가지 못해서 redux-saga에서 요청에 대해 결과를 기다리지 못하는 걸까요? 그리고 SSR 시 찍었던 console.log에 반응이 없습니다;;; export const getServerSideProps = wrapper . getServerSideProps (( store ) => async ({ req , res , ... etc }) => { console . log ( 'start' ); ... });

좋아요수
0
댓글수
7
조회수
896

질문&답변

새로고침 시 hydrate 상태 초기화 문제 질문 있습니다.

첫 로그인 시 req user에 정보가 잘 담겨 있습니다. 이후 정보는 계속 잘 담겨 있는데 브라우저에서 새로고침하면 정보는 그대로 있는데 요청에 대한 반응이 없습니다.

좋아요수
0
댓글수
7
조회수
896

질문&답변

getServerSideProps 사용관련 질문 있습니다.

import { wrapper } from '../store/configureStore' ; 와 import wrapper from '../store/configureStore' ; 두 방식의 차이점은 변수로 지정하냐 안하냐의 차이인가요?

좋아요수
0
댓글수
2
조회수
444