渲染不能用于反应功能

时间:2017-04-13 04:24:33

标签: javascript reactjs

我想知道为什么我不能在反应功能中使用渲染。下面的代码有错误。任何线索?

renderNewApplicants = (items) => {

    let new_applicants = items.filter(obj => 
        obj.applicants.result.is_new === true
    )

    render(){
        return( //map new_applicants here )
    }
 }

然后在jsx的其他地方我做{this.renderNewApplicants}

1 个答案:

答案 0 :(得分:1)

您可以从函数中返回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

相关问题