【发布时间】:2018-05-03 11:53:18
【问题描述】:
我有一个渲染之外的功能。该函数(有条件地)返回一个组件,该函数不是在渲染内部触发,而是在 componentWillReceiveProps 内部触发(由于其他事实,这是必要的)。 我的问题是函数最终没有返回组件,我不知道为什么。当我在渲染中调用该函数时,它可以工作,但我不能这样做,因为我必须在 componentWillReceiveProps 中调用它。有任何想法吗?谢谢!!
class App extends React.Component {
componentWillReceiveProps(nextProps) {
if (nextProps.user != this.props.user) {
this.getData(nextProps.user)
}
}
getData() {
if (...) {
return <Child />
}
}
render() {
return (
<div>{this.getData}</div>
);
}
}
const Child = () => {
return <h1>Hello</h1>
}
【问题讨论】:
标签: javascript reactjs