Docs
Internals
renderToTemplate()
⚠️

This function is part of the internal API. You should only be using this if you are making your own framework.


renderToTemplate()

Syntax: renderToTemplate(vnode, edits)
Example: renderToTemplate(<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' }]