Home
← All questions

renderDom: build DOM from a virtual node object | Frontend Machine Coding

MediumPremiumMachine Coding

Asked at Meta

Frontend Machine Coding interview practice: Create and append real DOM elements from a virtual-node description with type, props, and children.

Problem

Implement renderDom(vnode) that turns a virtual node into a real DOM element. A vnode looks like:

const vnode = {
  type: "div",
  props: { id: "app", style: { color: "red" } },
  children: [
    "Hello ",
    { type: "span", props: { className: "name" }, children: ["World"] },
  ],
};

Handle: element type, props (attributes + inline style object + className), and children (strings → text nodes, objects → recurse).

Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium