-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Rendering props.children without a wrapper #45
Comments
Hi @nightwolfz, Just return Here's your code with the added Cheers! |
Thanks @developit That works if you know that you will only have one child. Is it possible to return an array of children from the render method without wrapping? |
No, sorry :( - Neither React nor Preact support that. It has to do with tracking DOM Node ownership. I have a few thoughts around how it might be possible to implement, but they are all pretty bloated sadly. In my own work, the couple times I've wanted to do this I actually use a const ITEMS = [1, 2, 3, 4, 5];
const List = () => (
<div>
<h1>list of things:</h1>
<ul>
{ ListItems() }
</ul>
</div>
);
const ListItems = () => (
ITEMS.map( item => <li>{ item }</li> )
); |
You're right, I incorrectly assumed that React always returns |
@developit sad thing :-) Would be great to get "returning arrays" support. |
@developit I think Fiber is going to support this. Have you had any thoughts on this since your last reply? We've supported this in the past in Skate and it was quite convenient. |
I don't personally have a use for it, but I'm assuming it's a feature Preact will need to support. It doesn't fit well into the current model, but that's something I'm already changing. |
Is there anything new? Does 8.2.1 support it? |
There is an experimental PR: #703. |
You saved space on a Maybe class definition, which is fixed saving, but every component must have extra 3 letters. |
First of all, great job on Preact !
I noticed the following behavior being inconsistent with react unless there's a preact way of doing it.
It would be nice if we didn't need to wrap props.children with extra div's
Example:
The text was updated successfully, but these errors were encountered: