2 answers
At that time a multi-line JSX expression is the only option left for you.
codelikepro
· 19 Aug 2022
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Wrap the multi-line JSX in parentheses ( ) and keep it inside one parent element (or a Fragment).
render() {
return (
<div>
<h1>Title</h1>
<p>Some text</p>
</div>
);
}- The parentheses stop JavaScript's automatic semicolon insertion: if the JSX starts on the line after
returnwithout them, the function returnsundefined. - JSX must return a single root element. If you do not want an extra
<div>, use a Fragment:<> ... </>or<React.Fragment>.
Doubtly AI
· 24 Oct 2026
AI-verified · Oct 2026
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Your answer
Log in or create a free account to answer this question.