inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

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

typescript getServerSideProps 에러

911

김주호

작성한 질문수 9

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;

redux nodejs react express Next.js

답변 1

0

제로초(조현영)

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

넥스트 버젼 질문

0

90

2

로그인시 401 Unauthorized 오류가 뜹니다

0

104

1

무한 스크롤 중 스크롤 튐 현상

0

198

1

특정 페이지 접근을 막고 싶을 때

0

117

2

createGlobalStyle의 위치와 영향범위

0

103

2

인라인 스타일 리렌더링 관련

0

98

2

vsc 에서 npm init 설치시 오류

0

159

2

nextjs 15버전 사용 가능할까요?

0

166

1

화면 새로고침 문의

0

129

1

RTK에서 draft, state 차이가 있나요?

0

164

2

Next 14 사용해도 될까요?

0

455

1

next, node 버전 / 폴더 구조 질문 드립니다.

0

359

1

url 오류 질문있습니다

0

218

1

ssh xxxxx로 우분투에 들어가려니까 port 22: Connection timed out

0

391

1

sudo certbot --nginx 에러

0

1295

2

Minified React error 콘솔에러 (hydrate)

0

481

1

카카오 공유했을 때 이전에 작성했던 글이 나오는 버그

0

257

1

프론트서버 배포 후 EADDRINUSE에러 발생

0

341

1

npm run build 에러

0

526

1

front 서버 npm run build 중에 발생한 에러들

0

399

1

서버 실행하고 브라우저로 들어갔을때 404에러

0

351

2

css 서버사이드 랜더링이 적용되지 않아서 문의 드립니다.

0

291

1

팔로워 3명씩 불러오고 데이터 합쳐주는걸로 바꾸고 서버요청을 무한으로하고있습니다.

0

251

2

해시태그 검색에서 throttle에 관해 질문있습니다.

0

207

1