2017-04-13 76 views
0

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

renderNewApplicants = (items) => { 

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

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

然后在JSX别的地方我做{this.renderNewApplicants}

+0

你不能叫'render'在此way.Use'setState'更新将CLL渲染你的状态。 https://facebook.github.io/react/docs/state-and-lifecycle.html –

回答

1

您可以直接从你的函数返回您的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

+0

我懂了!谢谢! –