Skip to content
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

Passing single node as children does not seem to work with preact-hyperscript #43

Open
dmitriz opened this issue Apr 26, 2017 · 5 comments

Comments

@dmitriz
Copy link

dmitriz commented Apr 26, 2017

The Doc seems to allow passing single nodes as children but
when using with preact-hyperscript,
it seem that a single node can only be passed inside array:

  // this works
  div({style:{border: 'solid thin'}}, [div('hello')])

  // but this does not:
  // div({style:{border: 'solid thin'}}, div('hello'))

See the pen here:
http://codepen.io/dmitriz/pen/qmqYgY?editors=0011

Also referred in queckezz/preact-hyperscript#7
in case it is a problem on their end.

It would be nice to provide this feature from the helpers even if the host library h does not (which is sadly often the case).

@ohanhi
Copy link
Owner

ohanhi commented Apr 26, 2017

This library aims to be a very thin layer of sugar on top of whichever hyperscript implementation you are using. Like @staltz mentioned in the snabbdom issue, it is not trivial to tell nodes and other objects apart. Even more so since I wouldn't know which hyperscript library you are using. Because of these concerns, I am very reluctant to "polyfill" this functionality.

@staltz
Copy link
Contributor

staltz commented Apr 26, 2017

2 characters really cannot be so much bloat to type. React and (consequently) Preact did this "wrong" in my opinion from the beginning. It is much easier to distinguish (for both library code and some person reading code) what is props/data and what is children: the former is always an object, the latter always an array. I think React/Preact do this as some kind of optimization since their primary usage is through JSX. People using hyperscript (or non-JSX) wouldn't typically do this.

@dmitriz
Copy link
Author

dmitriz commented Apr 27, 2017

Thank you @ohanhi and @staltz for your comments. I presume you mean the way React makes look the same both arrays and single element, which is normal in HTML but confusing in JS indeed.

So does it mean, this line in the Readme should be corrected?

  • children is a hyperscript node, an array of hyperscript nodes, a string or an array of strings.

@ohanhi
Copy link
Owner

ohanhi commented Apr 28, 2017

Yes, I think adding the notion of "depending on your hyperscript library" could be helpful.

@dmitriz
Copy link
Author

dmitriz commented Apr 28, 2017

@ohanhi Is there any library doing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants