简体   繁体   中英

Nothing was returned from render

I have this error:

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

My code :

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,
}

I don't understand what wrong thanks

Seems like this.props.buttonRight is declared as a function but you are not calling it, you should call it in your render() like so this.props.buttonRight() . Make sure this.props.buttonRight() returns some JSX or null

Edit

A little note: when passing a function which returns some component, I'd recommend you call it renderSomething , for example renderButton . If you pass a Component instead, call it something or button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM