相关疑难解决方法(0)

只允许反应组件中特定类型的子项

我有一个Card组件和一个CardGroup组件,当CardGroup有子Card组件不是组件时,我想抛出一个错误.这是可能的,还是我试图解决错误的问题?

validation reactjs

41
推荐指数
7
解决办法
3万
查看次数

我如何解构 {this.props.children}?

我想为我的移动应用程序添加背景,但是当我使用“this.props.children”时,eslint 说我“必须使用解构道具分配”。为什么我可以解构这个道具?

这是我的代码,

export default class WallPaper extends Component {
  render() {
    return (
      <ImageBackground
        source={backgroundimg}
        imageStyle={{ opacity: 0.9 }}
        style={styles.container}
      >
        {this.props.children}
      </ImageBackground>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

当我使用此代码时

export default class WallPaper extends Component {
  render() {
    const { children } = this.props;
    return (
      <ImageBackground
        source={backgroundimg}
        imageStyle={{ opacity: 0.9 }}
        style={styles.container}
      >
        {children}
      </ImageBackground>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

我有这个错误“道具验证中缺少‘儿童’” 错误

当我使用此代码时,

export default class WallPaper extends Component {
  render() {
     (this.props) => {
    return (
      <ImageBackground
        source={backgroundimg}
        imageStyle={{ opacity: 0.9 }} …
Run Code Online (Sandbox Code Playgroud)

javascript destructuring node.js reactjs react-native

7
推荐指数
2
解决办法
4872
查看次数