A JSX expression must have exactly one outermost element.

Master ReactJS with our comprehensive test. Practice with multiple-choice questions and detailed explanations. Build your skills for the exam with our engaging format and expert tips!

Multiple Choice

A JSX expression must have exactly one outermost element.

Explanation:
In JSX, a single root element is required so React has one entry point to build and manage the element tree. If you want to render several elements, wrap them in one container element, such as a div, or use a Fragment so you don’t add an extra node to the DOM: <React.Fragment><Header /><Main /><Footer /></React.Fragment> or the shorter <> <Header /><Main /><Footer /> </>. This keeps the expression having exactly one outermost element. The other ideas don’t fit because multiple top-level elements aren’t allowed at the top level in JSX, and while components can render nothing by returning null, that doesn’t satisfy having a root element. Also, a fragment itself is the single outer element when you wrap multiple siblings, so there isn’t more than one root.

In JSX, a single root element is required so React has one entry point to build and manage the element tree. If you want to render several elements, wrap them in one container element, such as a div, or use a Fragment so you don’t add an extra node to the DOM: <React.Fragment>

</React.Fragment> or the shorter <>
</>. This keeps the expression having exactly one outermost element.

The other ideas don’t fit because multiple top-level elements aren’t allowed at the top level in JSX, and while components can render nothing by returning null, that doesn’t satisfy having a root element. Also, a fragment itself is the single outer element when you wrap multiple siblings, so there isn’t more than one root.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy