Mithril.js: Get component's HTML without mounting

Create a DocumentFragment and render the component to it.

Then there's no need to mount the component to the DOM.

const App = {
view: () => m('.foo', 'bar'),

const fragment = new DocumentFragment()
m.render(fragment, m(App))

//=> Element object

//=> Just the HTML: `<div class="foo">bar</div>`

Test the code on

DocumentFragment on MDN