2017-04-13 79 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

我懂了!謝謝! –