【发布时间】:2017-06-15 04:21:04
【问题描述】:
说我将 total_counts 从父组件传递给子组件。
在我的子组件中,我有一个渲染方法
render() {
console.log(this.props.pagination.total_counts )
}
如何正确使用 total_counts 而不会出错?我的孩子渲染方法可能会渲染多次,因为分页是通过 http 调用来的。如果我像下面那样进行解构
const { total_counts } = this.props.pagination
render(){
return (
<div>{total_counts && <p>{total_counts.toString()}</p>}</div>
)
}
我还是要检查 total_counts 是不是 undefined
【问题讨论】:
-
你的问题到底是什么?
-
试试
const { total_counts } = this.props.pagination? -
@D-reaper 如果
this.props.pagination未定义,如果我尝试渲染 total_counts,我的应用程序会中断吗?
标签: javascript reactjs jsx