강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

김주호님의 프로필 이미지
김주호

작성한 질문수

[리뉴얼] React로 NodeBird SNS 만들기

서버사이드렌더링 준비하기

typescript getServerSideProps 에러

작성

·

889

0

type script, redux toolkit으로 진행하고 있습니다.

getServerSideProps에서 type에러가 나고 있는데 검색으로도 해결이 어렵습니다. .ㅜㅜ

store설정에 문제가 있는걸까요 ..?

 

/pages/index.tsx

export const getServerSideProps = wrapper.getServerSideProps(
  async (context: any) => {
    context.store.dispatch(loadMyInfoRequest());
    context.store.dispatch(loadPostRequest(undefined));
    context.store.dispatch(END);
    await context.store.sagaTask.toPromise();
  }
);

//에러메세지
Argument of type '(context: any) => Promise<void>' is not assignable to parameter of type 'GetServerSidePropsCallback<EnhancedStore<any, AnyAction, SagaMiddleware<object>[]>, any>'.
  Type 'Promise<void>' is not assignable to type 'GetServerSideProps<any, ParsedUrlQuery, PreviewData>'.
    Type 'Promise<void>' provides no match for the signature '(context: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>): Promise<GetServerSidePropsResult<any>>'.

 

/store/config.ts

import { applyMiddleware, compose, configureStore } from "@reduxjs/toolkit";
import axios from "axios";
import createSagaMiddleware from "redux-saga";
import { all, fork } from "redux-saga/effects";
import { authSaga } from "../sagas/auth.saga";
import { postSaga } from "../sagas/post.saga";
import { createWrapper } from "next-redux-wrapper";
import { composeWithDevTools } from "@reduxjs/toolkit/dist/devtoolsExtension";
import rootReducer from "../reducers";

axios.defaults.baseURL = "http://localhost:3001";
axios.defaults.withCredentials = true;

const sagaMiddleware = createSagaMiddleware();

const middlewares = [sagaMiddleware];

const enhancer =
  process.env.NODE_ENV === "production"
    ? compose(applyMiddleware(...middlewares))
    : composeWithDevTools(applyMiddleware(...middlewares));

export const store = configureStore({
  reducer: rootReducer,
  middleware: [sagaMiddleware],
  devTools: process.env.NODE_ENV !== "production",
  enhancers: [enhancer],
});

function* rootSaga() {
  yield all([fork(authSaga), fork(postSaga)]);
}

sagaMiddleware.run(rootSaga);

const wrapper = createWrapper(() => store);
export default wrapper;

답변 1

0

제로초(조현영)님의 프로필 이미지
제로초(조현영)
지식공유자

이건 검색으로 해결할 게 아니라 사실 에러메시지를 읽으시면 됩니다. return {} 같은 것 넣으시면 해결될 듯 하네요.

김주호님의 프로필 이미지
김주호

작성한 질문수

질문하기