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 React Router Basics Navigating and Nesting Routes Organizing Your Routes

Why is he defining an object with parenthesis and not the curl brackets?

On 1:27 of this video he says,

"So, I'll create a routes object by typing const routes."

then created an like so,

const routes = ();

would it not be like this,

const routes = {};

is this an ES6 way of defining objets or JSX? I'm not 100% sure.

2 Answers

If you keep watching you'll see it's JSX. He's just defining it as empty for the moment.

I'm aware that it's not going to be empty, I just defined it with nothing inside so you can see what i'm talking about.

Ok so that means that {} is not how you define an object when using JSX but instead it's parenthesis.

{} is always how you define an object. JSX uses () for the inclusion of HTML/XML components. Since the Router and Routes are React components we're defining them in XML, hence the ().

Got it thanks Seth!

Keep in mind that () is not required, you can just as easily do

return <Router ...>
    ...
</Router >;

Which seems more legible to me. He switches between the two styles it seems.