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

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

实例代码:

  "首页"
            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

ReactNative使用TabBar报错react.children.only expected to receive a single react element child_第1张图片

解决办法:
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>

你可能感兴趣的:(react-native)