javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Update "Adjacent JSX elements must be wrapped in an enclosing tag" for React 16

Open akfranco opened this issue 9 years ago • 5 comments

React 16 does not require container elements. Is this going to be updated?

akfranco avatar Oct 01 '17 15:10 akfranco

Airbnb still uses React 15; however I'm not sure you're correct.

React 16 allows you to return an array of elements, but jsx syntax itself requires the enclosing tag.

Can you provide an example?

ljharb avatar Oct 01 '17 15:10 ljharb

@ljharb From the React 16 Docs:

render() {
  // No need to wrap list items in an extra element!
  return [
    // Don't forget the keys :)
    <li key="A">First item</li>,
    <li key="B">Second item</li>,
    <li key="C">Third item</li>,
  ];
}

monsonjeremy avatar Oct 02 '17 14:10 monsonjeremy

@monsonjeremy that's an array of elements; note the brackets.

If you removed those, you'd get a syntax error, since they'd need to be wrapped in an enclosing tag.

ljharb avatar Oct 02 '17 23:10 ljharb

I'm agreeing with @ljharb here and thinking there's nothing that's actually amiss with the current implementation. Feel free to close.

akfranco avatar Oct 06 '17 12:10 akfranco

I forgot a comma and also get this error.

natakina avatar Feb 01 '18 11:02 natakina