TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

React v16.2.0: Improved Support for Fragments

127 点作者 hswolff超过 7 年前

11 条评论

acemarke超过 7 年前
Several people had already noted [0] that you could implement equivalent behavior by using a component that simply returns its own children:<p><pre><code> const Fragment = ({children}) =&gt; children; &#x2F;&#x2F; later return &lt;Fragment&gt;&lt;Component1 &#x2F;&gt;&lt;Component2 &#x2F;&gt;&lt;&#x2F;Fragment&gt;; </code></pre> Nice to see this added as both a built-in component type and a useful syntax extension. (Now if they&#x27;d just modify JSX syntax so that we can pass props by matching local variable names similar to how ES6 object literals work, like `&lt;SomeComponent a b c &#x2F;&gt;`, rather than having that become a defaulted-true boolean, I&#x27;d be happy :) )<p>[0] <a href="https:&#x2F;&#x2F;medium.com&#x2F;@gajus&#x2F;using-react-v16-to-create-self-destructing-components-de8e4eb61d0f" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;@gajus&#x2F;using-react-v16-to-create-self-des...</a>
评论 #15803015 未加载
评论 #15803078 未加载
ojosilva超过 7 年前
Ive started with React recently and strangely the lack of fragments were one of the things that caught my attention in the first days.<p>Another thing I&#x27;m looking for in React as I get started is better styling support. I&#x27;m resourcing to React JSS for that, but I feel it should be part of the language. The <i>web trinity</i> if you may is HTML-CSS-JS and React basically left CSS out half-baked into almost unusable style attributes, so I still have to resource to className and CSS. Or am I just being noob-anal?
评论 #15805532 未加载
评论 #15805522 未加载
评论 #15805561 未加载
hobofan超过 7 年前
I appreciate the addition of Fragments, but I&#x27;m not sure if the addition to the JSX syntax was really a good decision.<p>While it initially took some time to wrap my head around JSX (especially with a lot of JS mixed into it), after that I really started to enjoy JSX for its simplicity. The Fragment syntax adds some additional magic to JSX (which is rarely a good thing), and will also very likely break all the syntax highlighting out there again when used.
评论 #15803322 未加载
slaymaker1907超过 7 年前
These will be quite nice when wrapping things like css grid components which must be on the same DOM level.
yladiz超过 7 年前
Man, although fragments are a pretty useful concept, the implementation is really terrible. It feels so uninspired and without thought of the design, in my opinion. They could have chosen some character instead of an empty tag and it would have been much better, like an asterisk[1], because it would be clear that the tag serves a defined purpose. I would almost argue that if this weird shorthand is necessary to accomplish this task (something that irked me when creating text heavy pages) then JSX should be redesigned to handle it natively without the weird fragment syntax.<p>1: Like this:<p><pre><code> &lt;*&gt; ... &lt;&#x2F;*&gt;</code></pre>
评论 #15808384 未加载
KeitIG超过 7 年前
I love to see these small improvements added to React.<p>Everything is not perfect though, some issues have been here for a looong time. At the moment, my biggest problem is the non-support of passive events [0]. And today, some browsers are starting to make some events passive by default (`touchmove` on Chrome for example), it is quietly starting to become a serious problem for developers to get things working fine cross-browser without anti-patterns.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;react&#x2F;issues&#x2F;6436" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;react&#x2F;issues&#x2F;6436</a>
borplk超过 7 年前
I was already thinking &quot;but what about Typescript...&quot; then saw it already supports it :)<p>Well done react team and contributors.
mcphage超过 7 年前
Why can&#x27;t they automatically wrap every bit of JSX with a &lt;Fragment&gt; tag? That way users would need to include an empty tag when they&#x27;re returning multiple elements, and they&#x27;re not it&#x27;ll be a fragment tag that just contains a single element.
评论 #15808311 未加载
Klathmon超过 7 年前
This is a bit off topic, but does anyone reading this happen to know the status of async rendering in react?<p>There was chatter about it for version 16, and then nothing really else. I&#x27;m curious about what they are testing or at least planning in this area.<p>Unfortunately i&#x27;ve found it really hard to search for anything related to async rendering for react, as there is just so much other crap about react and &quot;async&quot; it just gets lost.
评论 #15803045 未加载
评论 #15803042 未加载
评论 #15803054 未加载
megous超过 7 年前
No mention of prior work? This is part of web platform since forever. See document.createDocumentFragment().
评论 #15803345 未加载
Fifer82超过 7 年前
I just can&#x27;t help but sneer. Opinionated document.write() using &quot;jsx&quot;.<p>Working with react has been the worst experience of my life. I had to call a meeting and laid in down in October. If 2018 is React, I am leaving on Dec 31.<p>So soon I am going swiftly back into the arms of Angular and I can&#x27;t wait. Honestly, my eyes are blurring as I type this with pure happiness.<p>Enjoy the fragments guys, it will be good practice for picking up what little is left of your happiness and transferable skill set in years to come.
评论 #15803472 未加载
评论 #15804205 未加载
评论 #15803662 未加载
评论 #15803425 未加载
评论 #15805804 未加载
评论 #15803528 未加载