javascript - React.children.only 期望接收单个 react 元素子 Navigator

标签 javascript reactjs react-native react-redux

我尝试了太多主题帮助,但这并不能帮助我修复这个错误,也许是因为我是 react-native 的新手。

这是给出错误的代码。

render() {
  return (

  <Provider store={store}>

    <Navigator
      initialRoute={{ name: 'Wake' }}
      configureScene={(route, routeStack) => Navigator.SceneConfigs.FloatFromBottom}
      renderScene={RouteMapper}
    />

    <Tabs />



  </Provider>


 );
}

“React.children.only expected to receive a single react element child” 我在运行时收到此错误。请帮忙。 我知道有很多其他类似的主题发布,但没有一个能为我的问题提供适当的解决方案。

最佳答案

react-redux <Provider /> component 期望它的子 prop 是一个单一的 ReactElement,你的应用程序的根组件。这可能是此错误的来源。

Props

  • store (Redux Store): The single Redux store in your application.
  • children (ReactElement) The root of your component hierarchy.

Example

ReactDOM.render(
  <Provider store={store}>
    <div>
        <MyRootComponent/>
        <OtherComponent1/>
        <OtherComponent2/>
        // {...} as longer you let the component inside one global component 
        // - here the divs - React considers you have only one child. That it. 
    </div>
  </Provider>,
  rootEl
);

来源:https://github.com/reactjs/react-redux/blob/master/docs/api.md#provider-store

关于javascript - React.children.only 期望接收单个 react 元素子 Navigator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43300897/

相关文章:

javascript - 意外使用 'screen' no-restricted-globals reactjs

ios - 新的 React Native 项目失败 : Entry, ":CFBundleIdentifier",不存在

ios - React-Native:如何为动态链接的一个构建添加多个 google-service-info plist 文件?

javascript - 单击多种颜色更改单选按钮颜色

javascript - expo-video-player 出现问题,它会抛出错误 : setAudioModeAsync

javascript - window.open 后加载 CSS 文件

reactjs - 谷歌地图 react 没有出现

javascript - 返回变量时使用三元运算符而不是 if 语句

react-native - 为什么这个对 react-native native 模块的调用会阻塞 UI?

Javascript Promise 链接多个错误