在反应中使用es6计算状态的状态null错误

问题描述 投票:0回答:1

我在我的jsx中有这个

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

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

我无法运行应用程序,当我评论console.log行并执行此操作而不是console.log(this.state); console.log(o.sortKey),我有{ordercreated_at:'asc'}created_at,但为什么我的计算状态有空错误?

javascript reactjs ecmascript-6
1个回答
0
投票

while calling map method you must return something.

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

这里在map方法中返回一些东西,错误就会消失。

© www.soinside.com 2019 - 2024. All rights reserved.