說我將total_counts從父項傳遞給子組件。解構和在反應組件中使用道具
在我的孩子們組成部分我有一個渲染方法
render() {
console.log(this.props.pagination.total_counts)
}
如何使用正確共有TOTAL_COUNTS沒有錯誤?我的兒童渲染方法可能會多次渲染,因爲分頁是通過http調用來完成的。如果我desctructring像下面
const { total_counts } = this.props.pagination
render(){
return (
<div>{total_counts && <p>{total_counts.toString()}</p>}</div>
)
}
我還是要檢查共有TOTAL_COUNTS不是未定義
你的問題是什麼呢? –
嘗試'const {total_counts} = this.props.pagination'? –
@ D-reaper如果'this.props.pagination'未定義,我的應用會中斷,如果我嘗試呈現total_counts? –