Skip to content
Advertisement

React fragment shorthand failing to compile

The project in question is using React-16.2.0 which has the capability to use Fragments and the Fragment shorthand.

https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html

While the full-length syntax works fine…

JavaScript

The shorthand fails to compile and I am at a loss as to why this is. Fore example…

JavaScript

Which fails to compile as follows…

JavaScript

Is there something here I am missing about the Fragment shorthand syntax?

Advertisement

Answer

I think this is a reason:

https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html#support-for-fragment-syntax

screenshot

create-react-apps currently use Babel 6.26.0 for full support React.Fragment is needed Babel v7.0.0-beta.31 and above

======================= EDIT

It’s working now with create-react-app v2 https://reactjs.org/blog/2018/10/01/create-react-app-v2.html

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement