【问题标题】:Nothing was returned from render渲染没有返回任何内容
【发布时间】:2018-04-05 09:42:30
【问题描述】:

我有这个错误:

渲染没有返回任何内容。这通常意味着缺少 return 语句。或者,不渲染任何内容,返回 null。

我的代码:

export default class Header_page extends Component {
  render() {
    return (
      <Header>
        <Left>
          <Button transparent>
            <Icon name='ios-menu' />
          </Button>
        </Left>
        <Body>
          <Title>{this.props.title}</Title>
        </Body>
        <Right>
          <View>
            {this.props.buttonRight}
          </View>
        </Right>
      </Header>
    );
  }
}

Header_page.propTypes = {
  title: PropTypes.string.isRequired,
  buttonRight: PropTypes.func,
}

我不明白哪里错了 谢谢

【问题讨论】:

    标签: javascript reactjs react-native render


    【解决方案1】:

    似乎this.props.buttonRight 被声明为一个函数,但你没有调用它,你应该在你的render() 中调用它,就像this.props.buttonRight() 一样。确保 this.props.buttonRight() 返回一些 JSX 或 null

    编辑

    一点注意:当传递一个返回某个组件的函数时,我建议你将它命名为renderSomething,例如renderButton。如果您改为传递一个组件,请将其命名为 somethingbutton

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 2018-07-09
      • 2020-06-25
      • 1970-01-01
      • 2020-09-02
      相关资源
      最近更新 更多