ReactNative使用TabBar报错react.children.only expected to receive a single react element child

来源:互联网 发布:笨方法学python在线 编辑:程序博客网 时间:2024/06/07 01:38

ReactNative使用TabBar报错react.children.only expected to receive a single react element child

实例代码:

  <TabBarIOS.Item            title="首页"            icon={require('./img/动态副本.png')}            selected={this.state.selectedTab === '首页'}            onPress={() =>{              this.setState({                selectedTab:'首页',              });            }}>          </TabBarIOS.Item>//一运行就报错react.children.only expected to receive a single react element child

这里写图片描述

解决办法:
React Native 中无论是 TabBarIOS.Item 还是 TabBar.Item 必须有且只有一个组件,说白了就是需要有子组件的存在,并且只存在一个子组件。

  <TabBarIOS.Item            title="首页"            icon={require('./img/动态副本.png')}            selected={this.state.selectedTab === '首页'}            onPress={() =>{              this.setState({                selectedTab:'首页',              });            }}>            <View >                  <Text>首页</Text>             </View>          </TabBarIOS.Item>
1 0