JSX表达式不能使用逗号运算符。你是不是想写一个数组?

huangapple go评论64阅读模式
英文:

JSX expressions may not use the comma operator. Did you mean to write an array?

问题

I'm getting this error

JSX expressions may not use the comma operator. Did you mean to write an array?

on the following code snippets where I'm getting this error

<Text style={[theme.interRegular14], { fontWeight: 'bold' }}>No products bookmarked

I'm new to this codebase but found this error, but it didn't work.

Thanks

英文:

I'm getting this error

> JSX expressions may not use the comma operator. Did you mean to write an array?

on following code snippets where am getting this error

&lt;Text style={[theme.interRegular14], { fontWeight: &#39;bold&#39; }}&gt;No products bookmarked&lt;/Text&gt;

I'm new to this codebase but found this error but it didn't work.

Thanks

答案1

得分: 0

不要使用 ***`,`***相反你可以尝试这样做

```js
&lt;Text style={{fontWeight: &#39;bold&#39;,...theme.interRegular14 }}&gt;未收藏任何产品&lt;/Text&gt;

解释:

假设你有一个对象:

const theme = {
    interRegular14: {
      key1: &quot;value1&quot;,
      key2: &quot;value1&quot;
    }
}

当你使用 theme.interRegular14 时,你会得到以下数据:

{
    key1: &quot;value1&quot;,
    key2: &quot;value1&quot;
}

现在你可以使用这种方法将这个对象与新的键和值合并。

const newOBJ = {fontWeight: &#39;bold&#39;,...theme.interRegular14 }

现在这将返回最终的对象:

{
    fontWeight: &#39;bold&#39;,
    key1: &quot;value1&quot;,
    key2: &quot;value1&quot;
}
英文:

Don't use ,. Instead, you can try this:

&lt;Text style={{fontWeight: &#39;bold&#39;,...theme.interRegular14 }}&gt;No products bookmarked&lt;/Text&gt;

Explanation:

Let's say you have an object:

const theme = {
    interRegular14: {
      key1: &quot;value1&quot;,
      key2: &quot;value1&quot;
    }
}

And when you use theme.interRegular14. You get this following data:

{
    key1: &quot;value1&quot;,
    key2: &quot;value1&quot;
}

Now you can use this method to merge this object with new keys and values.

const newOBJ = {fontWeight: &#39;bold&#39;,...theme.interRegular14 }

Now this will return the final object as:

{
    fontWeight: &#39;bold&#39;,
    key1: &quot;value1&quot;,
    key2: &quot;value1&quot;
}

huangapple
  • 本文由 发表于 2023年4月10日 21:13:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977454.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定