我不知道为什么我不能在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即可删除render函数。

渲染仅用于类组件,而不能用于功能组件。

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 - 渲染不能在react函数中使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43383491/

10-12 00:21
查看更多