Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What TypeScript type should NextJS _app.tsx Component and pageProps be?

Tags:

Here's the default _app.tsx from NextJS:

function MyApp({ Component, pageProps }) {   return (     <Component {...pageProps} />   ) } 

The problem is, as soon as you switch to TypeScript, you get a warning under ES6Lint that these types are intrinsicly set to type 'any'. That being said, I can't figure out what type to set these two to that wont cause more errors later of mismatched types. What TypeScript types should I cast these two as?

like image 557
Citizen Avatar asked Nov 06 '20 23:11

Citizen


People also ask

Should you use TypeScript with NextJS?

Next. js has really good support for TypeScript and is easy to set up. That makes it simple to build strongly typed React apps with Next. js and TypeScript that run on either the client or the server.

What is the _APP js file in NextJS?

Use _app. js to extend react applications in Next. js. When using Next. js you'll most likely need to override the global App component to get access to some features like persisting state, or global layouts.

What is pageProps?

pageProps is an object with the initial props that were preloaded for your page by one of our data fetching methods, otherwise it's an empty object.


1 Answers

You could import the types from nextjs.

import { AppProps } from 'next/app';  function MyApp({ Component, pageProps }: AppProps) {   return <Component {...pageProps} /> } 
like image 52
kind user Avatar answered Nov 23 '22 15:11

kind user