如果条件为false,则我希望在有状态组件返回语句中显示类似于此的对象。
{ !this.state.searchCoin ? {displayCrypto} : null }为此,它将引发以下错误
对象作为React子对象无效
我的显示密码看起来像这样(在渲染中调用)
let displayCrypto = CryptoData.map(el => {
return (<CoinCard
no={i++}
key={el["short"]}
coinShortName = {el["short"]}
coinName = {el["long"]}
coinPrice = {el["price"].toFixed(2)}
marketCap = {(el["mktcap"]/1000000000).toFixed(4)}
percentChange = {el["perc"].toFixed(2)}
vwapData={el["vwapData"].toFixed(2)}
/>问题:如果条件为假,如何使用行程表达式在对象上显示?
如果你拒绝这个问题,请留下评论,以便我也能改进我的问题。
发布于 2018-08-24 11:26:26
只需删除{}:{ !this.state.searchCoin ? displayCrypto : null }
发布于 2018-08-24 10:25:38
您正在将cryptoCoinCard组件封装在括号中,这将提示错误。
移除{},它应该可以工作。
{ !this.state.searchCoin ? displayCrypto : null }https://stackoverflow.com/questions/52002009
复制相似问题