React · Junior · Question 7 of 75

How do you return two sibling elements from a component without an extra DOM wrapper?

Explanation

A component must return a single root. A fragment groups elements without adding a DOM node. If the fragment needs a key (e.g. in a list), use the full form <Fragment key={id}>. An array is also allowed, but each element needs a key, otherwise you get a warning.

Further reading

Problem with a question

React · Junior · question 7

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz