我在控制台中收到一条有趣的警告消息。我的警告消息是:警告:函数作为 React 子项无效。如果您返回一个组件而不是从渲染中返回,则可能会发生这种情况。或者也许您打算调用此函数而不是返回它。
这是什么意思?
这是我的应用程序中的返回代码:
render() {
return (
<Container>
<Row className="mt-2">
<Col md={4} className="pt-0">
<h2>Upload Timeframes</h2>
</Col>
<Col className="text-right" md={8}>
<Button onClick={() => this.setModalShow('create_window')}>
Add New Timeframe
</Button>
</Col>
</Row>
{this.activeTimeframeSection}
{this.futureTimeframeSection}
{this.archivedTimeframeSection}
</Container>
)
}
最佳答案
问题看起来您实际上并未调用函数 activeTimeframeSection
、futureTimeframeSection
和 archivedTimeframeSection
(缺少 ()
):
render() {
return (
<Container>
<Row className="mt-2">
<Col md={4} className="pt-0">
<h2>Upload Timeframes</h2>
</Col>
<Col className="text-right" md={8}>
<Button onClick={() => this.setModalShow('create_window')}>
Add New Timeframe
</Button>
</Col>
</Row>
{this.activeTimeframeSection()}
{this.futureTimeframeSection()}
{this.archivedTimeframeSection()}
</Container>
)
}
关于javascript - 警告 : functions are not valid as a react child question. ..是因为我的容器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60418234/