代码之家  ›  专栏  ›  技术社区  ›  Webwoman

nextjs-reactjs-invariant violation:react.children.only应接收单个react元素子级

  •  2
  • Webwoman  · 技术社区  · 6 年前

    我在和NextJS和ReactJS合作。我已经为我的应用程序UI设置了i layout.js文件。

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

    固定冲突:react.children.Only应接收单个 反应元素子级。

    这里是my 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>
    )
    

    我不知道怎么了,在我看来一切都很好,如果有人有任何暗示,那就太好了,

    thanks
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Webwoman    6 年前

    问题是我的数据结构与另一个框架对应。所以有一些微小的细节使得nextj在我的反应链接中像是“道具”的呼叫,这类东西。因此,如果有人有相同的问题,请仔细检查框架数据结构的配置。