r/javascript • • Jun 28 '18

The exact same app - 1 version made with React, Redux, and React-Router The other made with Vue, Vuex, Vue-Router. Good if you want to see both worlds. User Auth with JWT, note CRUD actions, Koa (Node) backend. MIT license.

https://johndatserakis.github.io/koa-react-notes-web/
459 Upvotes

98 comments sorted by

View all comments

Show parent comments

2

u/ihsw Jun 28 '18

<React.fragment> elements can be replaced with empty-bracket elements.

Eg:

<>
    {this.state.array.map(number=><span>{number}</span>)}
</>

And, furthermore, you can return bare arrays of rendered elements, so even that is unnecessary.

render() {
    return this.state.array.map(number=><span>{number}</span>);
}

1

u/NoInkling Jun 29 '18 edited Jun 29 '18

<React.fragment> elements can be replaced with empty-bracket elements.

Only with Babel 7, which is still in beta (and maybe Typescript?).

And, furthermore, you can return bare arrays of rendered elements, so even that is unnecessary.

You'll get a warning about missing keys though (which means it's less optimized).

Edit: actually the first example will also have the key issue, so you're right, there's no advantage to using the fragment in this case. Any time you use an array you should add keys though.