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

實例代碼:

  <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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章