Why not put an opening container element tag after the return keyword instead of an opening parentheses?

Question

Why not put an opening container element tag after the return keyword instead of an opening parentheses?

Answer

Although using an opening container element tag after the return statement will work, given that the first opening tag belongs to the same element as the final closing tag of the JSX expression and the first opening tag follows the return statement on the same line, it can make our code harder to read, it can make it less organized, and if we forget to put the first opening tag on the same line as the return statement, the JavaScript engine will automatically insert a semicolon after the return statement and will not return our component, but will instead stop executing the render() function.

8 Likes

is <> an open container tag?

6 Likes

I think it’s {}

1 Like

The opening and closing element tags is reference to HTML semantics. i.e I think we are referring to adding in

opening tag and
closing tags, instead of parenthesis. Basically, it will work using
tags but this opening tag has to be on same line as return statement,
i.e “return
…”.
otherwise if it is written as,
"return
.....". JSX compiler will think
is not part of return statement and therefore automatically add a semi-colon after return statement when code is compiled, which will lead to errors I'm guessing. Using parenthesis does away that error. Please correct me if i'm wrong here.

Thanks,

H

1 Like

How correct is it to use ‘opening container element tag’ phrase rather than ‘container element opening tag’?
It took me at least 5 minutes to understand what you are saying.

And last excuse ( if we forget to put the first opening tag on the same line as the return statement, the JavaScript engine will automatically insert a semicolon after the return statement) to not use element tags after ‘return’ is valid for ‘opening parentheses’ as well, which makes it invalid excuse when comparing ‘opening tags’ and ‘opening parentheses’.

1 Like