News for hackers. Stuff that matters.
Re:React v16.2.0: Improved Support for Fragments by acdlite on Tuesday November 28, 2017 @07:14PM (#15803322)
> The Fragment syntax adds some additional magic to JSX (which is rarely a good thing)

In: <></>

Out: <React.Fragment></React.Fragment>

WITCHCRAFT!! SORCERY!!

Teasing aside, I don't get what's magical about this. It's a straightforward transform. You can call that "magic," I'll call it "syntax."

Re:React v16.2.0: Improved Support for Fragments by hobofan on Tuesday November 28, 2017 @07:22PM (#15803363)
Sure, we can call it syntax. Of course, for anyone who already knows what it does, it's just a transform, but the problem with extra syntax is that it makes it harder for newcomers to pick it up.

Taking your example when putting it in front of someone seeing it for the first time:

In: <></>

Out (Newcomer): WTF does that mean? Did someone forget to put something in those tags?

Re:React v16.2.0: Improved Support for Fragments by danabramov on Tuesday November 28, 2017 @07:38PM (#15803446)
Same newcomer, in a couple of weeks: "Don't know how I lived without it".

I understand your point, but in practice people love tiny affordances like this, especially when they are needed as often as fragments are.

This is a balance, but it's important to consider the needs of power users too. Beginners don't stay beginners forever. We've thought about this for a few months, and decided that adding syntax would be better. I understand some people will always disagree though, and that's fine :-)

Re:React v16.2.0: Improved Support for Fragments by electric_sheep on Wednesday November 29, 2017 @07:35AM (#15806287)
Yeah, it seems like the decision to make the fragment a first-class JSX concept has a lot to do with portability between renderers. The post makes it clear you all have given this a lot of thought and care, and I appreciate that (even if it will take me awhile to get used to seeing empty tags, haha).
Re:React v16.2.0: Improved Support for Fragments by hazza1 on Tuesday November 28, 2017 @10:05PM (#15804206)
Sure it's straightforward enough and much better than what we had before.

But for a newcomer to JSX it looks odd.

I'm probably just missing the reason for the syntax, we're already compiling - why can't fragments be added automatically as required?

Re:React v16.2.0: Improved Support for Fragments by electric_sheep on Wednesday November 29, 2017 @07:39AM (#15806305)
I'm guessing it's because JSX is XML-like and so parsers may require a single root element for each JSX "document". It's a good question though, hopefully someone from the React team might be able to comment.
Re:React v16.2.0: Improved Support for Fragments by danabramov on Wednesday November 29, 2017 @12:01PM (#15808442)
Because it is ambiguous. :-)

https://news.ycombinator.com/item?id=15808311

If you have a specific proposal for how it should work, I'm happy to look at it and try to poke holes in it.

Re:React v16.2.0: Improved Support for Fragments by electric_sheep on Thursday November 30, 2017 @10:09PM (#15821612)
It would be, wouldn't it. Silly I didn't realize that right off the bat.

Can't imagine putting forward a proposal that wouldn't in essence be what you're doing, i.e. wrapping in JSX delimiters. Because attempting anything fancier than that would probably have edge cases for days, plenty of material for you to poke holes in.