Matt-Esch/virtual-dom

Hyperscipt doesn't work inside of map/loop

8483 opened this issue · 0 comments

8483 commented

I am trying to create virtual table rows with a loop, but they don't appear.

The rendering works, but only to the tbody. This is the resulting HTML.

<div>
    <table>
        <tbody></tbody>
    </table>
</div>

The code

var h = require('virtual-dom/h');
var createElement = require('virtual-dom/create-element');

function view(state) {

    function renderRows() {
        var rows = []
        for (var i = 0; i < state.items.length; i++) {
            var item = state.items[i]
            rows.push(
                h('tr', [
                    h('td', item.documentDate),
                    h('td', item.documentKey)
                ])
            )
        }
        return rows
    }

    let tableRows = renderRows()

    return h('div', [
        h('table', [
            h('tbody', tableRows)
        ])
    ]);
}

var tree = view(state);
var rootNode = createElement(tree);
document.getElementById("app").appendChild(rootNode);

How can I get this to work?