Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 following code snippets where am getting this error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

Thanks

>Solution :

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

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

Explanation:

Let’s say you have an object:

const theme = {
    interRegular14: {
      key1: "value1",
      key2: "value1"
    }
}

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

{
    key1: "value1",
    key2: "value1"
}

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

const newOBJ = {fontWeight: 'bold',...theme.interRegular14 }

Now this will return the final object as:

{
    fontWeight: 'bold',
    key1: "value1",
    key2: "value1"
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading