Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Barry Lachapelle
Barry Lachapelle
1,801 Points

using return () in components

I notice when creating react components sometimes the tutorials are using

const comp = props => { return ( jsx in here ) }

and sometimes just leaving them in the pointer function

const comp = props => jsx in here

Is there any situation to use either or are both ok?

2 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

From my understanding, you want to use an explicit return if there are multiple lines or your code is in a block (i.e. {}). If it's a one liner, an implicit return may look cleaner, but it's personal choice on which you prefer to use in the long run.

Both are alright, but for longer JSX snippets I prefer parentheses.