http://blog.csdn.net/meiyulong518/article/details/70748903
ReactNative使用TabBar报错react.children.only expected to receive a single react element child
实例代码:
<TabBarIOS.Itemtitle="首页"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>
<TabBarIOS.Item title="首页"icon={require('./img/动态副本.png')}selected={this.state.selectedTab === '首页'}onPress={() =>{this.setState({selectedTab:'首页',});}}><View ><Text>首页</Text></View></TabBarIOS.Item>