Docs
renderToTemplate()

This function is part of the internal API. Only use if you know what you are doing and are optimizing for performance.


renderToTemplate()

Syntax: stringToDOM(vnode, edits)
Example: stringToDOM(<div>Hello World</div>, [])

The renderToTemplate() function is used to render a virtual DOM node to a string. This is used to create the template for the block and works tangentially with stringToDOM().

import { renderToTemplate } from 'million';
 
const edits = [];
const template = renderToTemplate(<div>Hello World</div>, edits);
 
console.log(template); // '<div>Hello World</div>'
 
console.log(edits); // []

Holes in templates

You can also pass in Holes to the renderToTemplate() function. This will return the template with edits.

import { renderToTemplate } from 'million';
 
const edits = [];
const hole = { $: 'hole' };
const template = renderToTemplate(<div>Hello {hole}</div>, edits);
 
console.log(template); // '<div>Hello </div>'
 
console.log(edits); // [{ type: 'child', index: 0, hole: 'hole' }]