'_app.tsx to have getInitialProps and other custom props too, need proper Typscript type
My _app.tsx files what to be something on these lines
interface CmsAppProps extends AppProps {
pageData: boolean
}
const CmsApp: NextPage<CmsAppProps> = ({ Component, pageProps, pageData }) => {
// ...some component details
}
CmsApp.getInitialProps = async (context: NextPageContext) => {
// some data process here
return {
pageData: true
}
}
Problem here is, typescript is throwing error as: Type '(_ctx: NextPageContext) => Promise<{ pageData: true; }>' is not assignable to type '(context: NextPageContext) => CmsAppProps | Promise<CmsAppProps>'
Looks like it expense me to return data same as what is argument of component props. I cannot return Component and pageProps from getInitialProps.
If I replace type NextPage with React.FC then it obviously doesn't contain getInitialProps props. Plus doesn't has relation like what is being sent from getInitialProps also will be passed on to the component.
Is there a correct way to put everything right in typescript?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
