-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper functions for fragments #319
Comments
Could you try There is also createFrament addon: https://reactjs.org/docs/create-fragment.html I tried checking React code if there is way to extend React to understand other data-structures as fragments (though that might anyway be bad idea) but didn't find anything. And it might be hard in Reagent to automatically detect which returns values are fragments. Only |
Hmm. The array solution is nice. It would also be nice to have native |
This one is useful for e.g. conditionally creating 1 or 2 elements:
Do we need another, non-vargs, version? For cases when using |
Could something like (defn <> [& children]
(apply array (map r/as-element (keep identity children)))) And then: [<>
"Some text."
[:h2 "A heading"]
"More text."
[:h2 "Another heading"]
"Even more text."] work, to mirror the jsx syntax? render() {
return (
<>
Some text.
<h2>A heading</h2>
More text.
<h2>Another heading</h2>
Even more text.
</>
);
} |
Interesting. I never saw that syntax but yes, that would be possible. |
Interesting, but I prefer the fragments version. Looks better in JSX because they use |
I get this when I try to return an array using the suggested snippet above:
|
I'm not a reagent user but I think the CLJS community should come together and decide on a hiccup syntax to define fragments so they're the same in Sablono, Rum & Reagent (and possibly even Hiccup itself). Other tickets:
I'd personally vote for one of the following: [:* {:key x} child0 child1]
[:* child0 child1]
[:<> child0 child1]
[:<> {:key x} child0 child1] With preference to As an aside: There is probably more features coming to React which might warrant more hiccup syntax: |
Can I chime in and "vote" ? I agree with the usage of a keyword, it makes everything much easier. My preference would go to |
React 16.2 Added more fragment support. https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html Perhaps the syntax should be |
https://reactjs.org/docs/react-component.html#fragments
Add support for fragments.
e.g.
Should return a fragment when called with
[sample-component (range 6)]
.The text was updated successfully, but these errors were encountered: