遵循https://nextjs.org/docs/basic-features/layouts#with-typescript指南,修改了我想要使用布局的Home
页和_app.tsx
页.
指南没有显示Layout.tsx
应该是什么样子,而且它目前的错误是:
键入"{children:ReactElement<;any,string"|
我是TS新手,不知道如何将页面传递到布局.
遵循https://nextjs.org/docs/basic-features/layouts#with-typescript指南,修改了我想要使用布局的Home
页和_app.tsx
页.
指南没有显示Layout.tsx
应该是什么样子,而且它目前的错误是:
键入"{children:ReactElement<;any,string"|
我是TS新手,不知道如何将页面传递到布局.
错误消息可能会让人非常困惑.
首先,要将组件page
传递到布局组件中,需要在<Layout>
标记中添加一个属性,该属性的名称为prop,在本例中为"children",如下所示:<Layout children={page}><Layout/>
.有关更多信息,请查看此来源:https://reactjs.org/docs/components-and-props.html
此外,功能组件只接受一个"prop"对象作为函数的参数,它是一个包含其他属性的对象.更多信息,请查看第https://fettblog.eu/typescript-react/components/页.
export default function Layout (props : { children : string }) { ...