gpt4 book ai didi

javascript - Nextjs - Reactjs - 不变违规 : React. Children.only expected to receive a single React element child

转载 作者:行者123 更新时间:2023-11-29 16:02:00 24 4
gpt4 key购买 nike

我正在使用 Nextjs 和 Reactjs。我已经为我的应用程序 UI 设置了 Layout.js 文件。

我想知道为什么我的控制台返回我:

Invariant Violation: React.Children.only expected to receive a single React element child.

这是我的 layout.js :

export default ({ children, title = 'This is the default title' }) => (
<div>
<Head>
<title>{ title }</title>
<meta charSet='utf-8' />
<meta name='viewport' content='initial-scale=1.0, width=device-width' />
</Head>
<div className={style.layout}>
<div>
<div className={style.header}>
<div className= {style.headbar}>
<div className={style.headerLeft}>
<Logo className={style.logo}/>
</div>
<div className={style.headerRight}>
<MenuContainer className={style.menu}/>
</div>
</div>
<div className={style.chatbox}>
<ChatContainer/>
</div>
</div>

{ children }

<div className={style.footer}>
<Link to="/quote" className={style.quote}>
Click here
</Link>
<SocialMedia/>
<Subscription/>
</div>
</div>
</div>
</div>
)

我的 wrappedComponent.js:

const Index = () => (
<Provider store={store}>
<Layout>
<Home/>
</Layout>
</Provider>
)

我不知道哪里出了问题,在我看来一切都很好,如果有人有任何提示,那就太好了。

谢谢。

最佳答案

问题是我的数据结构对应于另一个框架。所以有一些微小的细节让 NextJS 崩溃——比如我的 React 链接中的“props”调用,这类东西。所以如果有人有同样的问题,仔细检查你的框架数据结构的配置

关于javascript - Nextjs - Reactjs - 不变违规 : React. Children.only expected to receive a single React element child,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51757436/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com