question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pass single node in place of children?

See original GitHub issue

Right now this seems illegal:

    // works
    h('div', {className: 'new-style'}, [node])

    // does not work!
    h('div', {className: 'new-style'}, node)

because of

export function h(sel: string, children: Array<VNode | undefined | null>): VNode;

(https://github.com/snabbdom/snabbdom/blob/master/src/h.ts#L19)

The latter seems to be cleaner and less cluttered though. Would it be possible to support?

Here is some further motivation with examples:

https://github.com/queckezz/preact-hyperscript/issues/7

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dmitrizcommented, Apr 29, 2017

@caesarsol You are right, it does work indeed here, lol 😉

It didn’t work with Preact-hyperscript, so I must have mixed things up.

I guess I should perhaps close this issue then.

0reactions
caesarsolcommented, Apr 29, 2017

I’m using snabbdom in JS and the single child syntax works!

Take a look at https://github.com/snabbdom/snabbdom/blob/master/src/h.ts#L32 in which the second and third arguments are checked for presence of .sel (to identify a vnode) and assigned to children as single-element array.

I’m guessing it’s only forbidden by TS signature.

(Or am I missing something?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update a single child node from a list of ... - GitHub
I have an Explorer Treeview and a parent in the tree can have hundreds of child nodes. Each child node then has right...
Read more >
How to initialize a child process with passed in functions in ...
The problem I'm running into is that, when using Child Processes in NodeJS, you can't pass functions to the child process and my...
Read more >
How To Launch Child Processes in Node.js - DigitalOcean
With our script in place, we can write a new Node.js module to execute it. This script will use execFile() to run the...
Read more >
Node.js Child Processes: Everything you need to know
Single -threaded, non-blocking performance in Node.js works great for a single process. But eventually, one process in one CPU is not going ...
Read more >
React Children And Iteration Methods - Smashing Magazine
In this article, we'll discuss and learn about the use case of iterating over React `children` and the ways to do it. In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found