getServerSideProps의 인자

김민석·2021년 6월 23일
0

NodeBird 클론코딩

목록 보기
10/10

이것을 찾게된 이유는 client에서 POST localhost:3000/post/[1]이런 식으로 동적 라우팅을 할 때, parameter를 getServerSidePriops 안으로 어떻게 넘겨 주어야 할지 생각하다가 발견하게 되었다.

getServerSideProps는 인자로 커링함수를 받는다.
이때, outer 함수는 store를 인자로 받고,
inner 함수는 req,res,...etc로 표시 되어있다.

import React from 'react';
import {connect} from 'react-redux';
import {wrapper} from '../store';

export const getServerSideProps = wrapper.getServerSideProps(store =>
    ({req, res, ...etc}) => {
  	console.log(etc) // 이것의 결과가 아래 사진이다.
        console.log('2. Page.getServerSideProps uses the store to dispatch things');
        store.dispatch({type: 'TICK', payload: 'was set in other page'});
    }
);

// Page itself is not connected to Redux Store, it has to render Provider to allow child components to connect to Redux Store
const Page = ({tick}) => (
    <div>{tick}</div>
);

// you can also use Redux `useSelector` and other hooks instead of `connect()`
export default connect(state => state)(Page);

이 사진은 ...etc 부분을 콘솔로그로 찍어본 것이다. 발견!

0개의 댓글