反应原生 - 无效的道具子项



我创建了几个组件。其中一个应该允许嵌套,但它莫名其妙地不允许(莫名其妙,因为我找不到任何有这个问题的帖子(

运行此映像需要一张映像(可以用任何内容替换(

import React, {Component} from 'react';
import PropTypes from 'prop-types';
import { View, StatusBar, StyleSheet, ImageBackground } from 'react-native';
export class PhonyStatusBar extends Component {
render () {
return (
<View style={styles.statusBar} />
);
}
}
export class HomeScreen extends Component {
static propTypes = {
children: PropTypes.string
}
render () {
return (
<View>
{this.props.children}
</View>
);
}
}
export class AppGrid extends Component {
render () {
return (
<View />
);
}
}
export default class App extends Component {
render() {
return (
<View>
{/* hide system status bar */}
<StatusBar hidden={true} />
<PhonyStatusBar />
{/* throw in our own status bar  */}
<HomeScreen> 
<View />
</HomeScreen>
</View>
);
}
}
const styles = StyleSheet.create({
backgroundImage: {
width:'100%',
height:'100%',
},
statusBar: {
width: '100%',
height: 25.33,
backgroundColor: 'rgba(255, 157, 0, 0.5)'
},
});

在 reactchildren中是一个内置的 prop,已经由库定义,用于组件。这不是您应该手动定义的道具。有关更多详细信息,请参阅以下内容:https://reactjs.org/docs/jsx-in-depth.html#children-in-jsx

尝试删除:

static propTypes = {
children: PropTypes.string
}

HomeScreen来解决问题。

最新更新