Skip to content
doubtly

2 answers

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 return without them, the function returns undefined.
  • 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?

Your answer

Log in or create a free account to answer this question.