LoginSignup
4
0

More than 1 year has passed since last update.

NextPageって使わなくちゃだめ?? React.FCとどう違うの?

Posted at

React.FCNextPageってどう違う?

型自体について

React.FC

type FC<P = {}> = React.FunctionComponent<P>

だいぶ汎用的

対してNextPage

type NextPage<P = {}, IP = P> = React.ComponentType<P> & {
    getInitialProps?(context: NextPageContext): IP | Promise<IP>;
}

となっています.
大きな違いはgetInitialPropsでしょう.

getInitialPropsについて

getInitialPropsのドキュメントによると

getInitialProps enables server-side rendering in a page and allows you to do initial data population, it means sending the page with the data already populated from the server. This is especially useful for SEO.

ちなみに

pagesの公式ドキュメントによると

By default, Net.js is pre-renders every pages.

まとめ

  • React.FCはその名の通り一般的な関数型コンポーネントに対して用いることができる型.pageに対しても使用することはできると思う.
  • pageを構成するコンポーネントに必要な要素が絞れる(さらにNextjsではroutingのシステムを提供している)ため,Nextjs側がpageを構成するコンポーネントを定義することで,routingシステムをより強く設計でき

pageコンポーネントにはNextPageを使おう

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0