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>