hyperscript icon indicating copy to clipboard operation
hyperscript copied to clipboard

table virtual html example incorrect in "children -Array' section

Open rickdog opened this issue 9 years ago • 1 comments

children - Array

Each item in the array is treated like a ordinary child. (string or HTMLElement) this is useful when you want to iterate over an object:

var h = require('hyperscript')
var obj = {
  a: 'Apple',
  b: 'Banana',
  c: 'Cherry',
  d: 'Durian',
  e: 'Elder Berry'
}
h('table',
  h('tr', h('th', 'letter'), h('th', 'fruit')),
  Object.keys(obj).map(function (k) {
    return h('tr',
      h('th', k),
      h('td', obj[k])
    )
  })
)

table should be:

h("table", 
[
  h("tr", [ h("th", "letter"), h("th", "fruit") ]),
  Object.keys(obj).map(function (k) { 
    return h('tr',
      [ h('th', k), h('td', obj[k]) ]
    ) 
  })
])

rickdog avatar Apr 30 '15 07:04 rickdog

no either will work, you can do h(tag, <child1>, <child2>, <child3>) OR h(tag, [<child1>, <child2>, <child3>]) and that is the same. You can also do h(tag, <child1>, [<child2>, <child3>]) or h(tag, [<child1>, <child2>], <child3>)

It is all treated as the same, which makes maps over arrays etc.

dominictarr avatar May 04 '15 08:05 dominictarr