graphql-codegen-apollo-next-ssr icon indicating copy to clipboard operation
graphql-codegen-apollo-next-ssr copied to clipboard

Use `NextPage` for PageComp type instead of `React.FC`

Open rohit-gohri opened this issue 4 years ago • 1 comments

Currently Page Component types get generated using React.FC but it should be using NextPage

Current:

import type React from 'react';

export type PageAllOrdersComp = React.FC<{data?: AllOrdersQuery, error?: Apollo.ApolloError}>;

Expected

import type { NextPage } from 'next';

export type PageAllOrdersComp = NextPage<{data?: AllOrdersQuery, error?: Apollo.ApolloError}>;

rohit-gohri avatar Oct 13 '21 08:10 rohit-gohri

Just noticed that this is being used for withHooks and I guess the main usecase is not to import and use it in page component itself?

Edit: Would it make sense to export something like this too for use with getServerSideProps:

const ServerPage = `export type ${pageOperation}Page = NextPage<{data?: ${operationResultType}, error?: Apollo.ApolloError}>;`;

rohit-gohri avatar Oct 13 '21 08:10 rohit-gohri

is there any substancial difference between NextPage and React.FC ?

alete89 avatar Nov 08 '22 20:11 alete89

There was some usecase related to inference and InferProps not working without the type being based on NextPage. But I don't remember the specifics now. I'll close this

rohit-gohri avatar Nov 08 '22 23:11 rohit-gohri