hyperscript
hyperscript copied to clipboard
table virtual html example incorrect in "children -Array' section
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]) ]
)
})
])
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.