-
Notifications
You must be signed in to change notification settings - Fork 30
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
Use preact Fragment to render multiple children #37
Conversation
When `wrap = true`, `preact-markup` only renders the first child. Using Fragments, `preact-markup` can render all the children without wrapping them with a `<div />`.
@developit Would you mind merging this? |
@developit @marvinhagemeister what do you think of this PR? |
src/index.js
Outdated
@@ -49,7 +49,7 @@ export default class Markup extends Component { | |||
} | |||
} | |||
|
|||
if (wrap===false) return vdom && vdom[0] || null; | |||
if (wrap===false) return vdom && h(Fragment, {}, vdom) || null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for Fragment here - this line can just return the array:
if (wrap===false) return vdom || null;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Good idea! I left a suggestion to simplify things. I'm actually thinking we can just drop the wrap parameter now, since this component can just always return the array of elements. |
Thanks @developit! I applied your suggestion. For backwards compatibility, maybe we can keep the |
@hpneo yeah that works for me! |
When
wrap = true
,preact-markup
only renders the first child. Using Fragments,preact-markup
can render all the children without wrapping them with a<div />
.