function Items() {
return (
<div>
<li>Apples</li>
<li>Pears</li>
<li>Plums</li>
</div>
);
}
<ul><Items /></ul>
The
<div> sits between <ul> and <li>, which breaks the list structure. Return a Fragment insteadA <ul> may only contain <li> elements (and script-supporting elements). The extra <div> breaks the parent-child link, so the browser may not expose a proper list with a count. Returning <>…</>, a Fragment, adds no DOM element, so the <li>s become direct children again. The same problem happens with <tr> inside a wrapper div in tables.
"React removes <li> elements" is the tempting wrong answer. React renders exactly what you return. The problem is the invalid HTML. key props are only for React's own updates, and screen readers never see them.
Read more