简体   繁体   中英

Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes' on react layout component

This is the code for the layout

import type { NextPage } from 'next'
import React from 'react'
 
interface LayoutProps {
 children: React.ReactNode;
}
 
const Layout: NextPage = ({ children }: LayoutProps) => {
 return (
   <>
     <div>
       <main>
         {children}
       </main>
     </div>
   </>
 );
};
 
 
export default Layout

The error appears when I hover over the start of the layout element in this block of code which is the main part of the app.

import type { AppProps } from 'next/app'
import Layout from '../components/Layout'
import '../styles/globals.css'
 
function MyApp({ Component, pageProps }: AppProps) {
 return (
   <Layout>
     <Component {...pageProps} />
   </Layout>
 )
}
export default MyApp

I thought at first that it was because I didn't have the right type for the children but I made a type for the children but I made an interface for that but I still am receiving the error.

Try with generics

import type { NextPage } from 'next'
import React from 'react'
 
interface LayoutProps {
 children: React.ReactNode;
}
 
const Layout: NextPage<LayoutProps> = ({ children }) => {
 return (
   <>
     <div>
       <main>
         {children}
       </main>
     </div>
   </>
 );
};
 
 
export default Layout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM