我有这个错误:
Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, 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,
}
我不明白哪里错了 谢谢
最佳答案
似乎 this.props.buttonRight
被声明为一个函数,但您没有调用它,您应该像这样在 render()
中调用它 this.props.buttonRight()
。确保 this.props.buttonRight()
返回一些 JSX 或 null
编辑
注意事项:当传递一个返回某个组件的函数时,我建议您将其命名为renderSomething
,例如renderButton
。如果您改为传递一个组件,请将其命名为 something
或 button
关于javascript - render 没有返回任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46913126/