我想知道为什么我不能在react函数中使用render。下面的代码有错误。有什么线索吗?
renderNewApplicants = (items) => {
let new_applicants = items.filter(obj =>
obj.applicants.result.is_new === true
)
render(){
return( //map new_applicants here )
}
}
然后在 jsx 的其他地方我做 {this.renderNewApplicants}
最佳答案
您只需从函数中返回 JSX 即可删除渲染函数。
渲染仅在类组件中使用,不在函数组件中使用。
renderNewApplicants = (items) => {
let new_applicants = items.filter(obj =>
obj.applicants.result.is_new === true
)
return(<div> some markup here.</div>);
}
查看此处的文档 https://facebook.github.io/react/docs/components-and-props.html
关于javascript - render不能在react函数中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43383491/