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

Return content without parentheses

I’m using Next.JS (13) and I was wondering if there is any problem in writing the code like this:
not using parentheses

Instead of:
using parentheses

Is there any difference between the results?

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

I tested both but I didn’t see any difference, I started using React a short time ago, and I can’t say if in larger projects there is any difference…

>Solution :

From the perspective of the ‘react compiler’, there is no difference as in both cases you return a React.Fragment object.

However, from my experience, when using javascript there are a couple of situations when you want to use parentheses.

For example, when you want to have a lambda function that returns an object:

()=>{prop:'My Object'} // syntax error as the lambda is considering the object declaration as a function body

()=>({prop:'My Object'}) // works

Or, some vscode extensions might be confused about not using parentheses, so for example, one might autocomplete and put a ‘;’ in the wrong place:

  ()=><p> ;            // semicolon in the wrong place
     Some text </p>

Hope it helps!

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