[英]Error: Objects are not valid as a React Child
I want to display an object if the condition is false for which I was doing something like this in my stateful component return statement. 如果条件为false,我想显示一个对象,为此我在有状态组件return语句中执行了类似的操作。
{ !this.state.searchCoin ? {displayCrypto} : null }
For this, it is throwing the following error 为此,它引发以下错误
Objects are not valid as a React Child
对象无效作为React子代
My display crypto looks something like this (called in render) 我的显示密码看起来像这样(称为渲染)
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)}
/>
[Question:] How can we I use itinerary expression to display on object if the condition is false? [问题:]如果条件为假,如何使用行程表达式在对象上显示?
Ps: If you are downvoting this question then please leave a comment as well so that I can improve my question as well. 附言:如果您对此问题不满意,请也发表评论,以便我也可以改善我的问题。
You are wrapping the cryptoCoinCard
components in brackets this prompts the error. 您将
cryptoCoinCard
组件包装在方括号中,这将提示错误。
Remove the {}
and it should work. 删除
{}
,它应该可以工作。
{ !this.state.searchCoin ? displayCrypto : null }
Just remove the {}
: { !this.state.searchCoin ? displayCrypto : null }
只需删除
{}
: { !this.state.searchCoin ? displayCrypto : null }
{ !this.state.searchCoin ? displayCrypto : null }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.