简体   繁体   English

使用es6中已计算状态的状态为null的错误

[英]state null error using es6 computed state in react

I have this in my jsx 我的jsx中有这个

<tr>
{!isEmpty(content) && content.map(o => {

                    if(o.sortKey){ console.log(this.state[`order${o.sortKey}`]) }
})}
</tr>

I couldn't run the app, When I commented the console.log line and do this instead console.log(this.state); console.log(o.sortKey) 我无法运行该应用程序,当我注释了console.log行并执行此操作时,改为console.log(this.state); console.log(o.sortKey) console.log(this.state); console.log(o.sortKey) , I have {ordercreated_at:'asc'} and created_at but why my computed state has null error? console.log(this.state); console.log(o.sortKey) ,我有{ordercreated_at:'asc'}created_at但是为什么我的计算状态{ordercreated_at:'asc'}错误?

while calling map method you must return something. 在调用map方法时,您必须返回一些内容。

content.map (o => { return (<span></span>)})

here in map method return something and error will go away. 在map方法中返回错误,错误将消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM