Problem, as an interviewer would state it:
"Implement createElement(vnode) — converting a simple {tag, props, children} vnode tree into an actual, real DOM element, including correctly wiring up event handlers."
Examples:
createElement(h("div", { class: "box" }, h("span", {}, "Hello")));
// a real, live <div class="box"><span>Hello</span></div> DOM element
Clarifying questions expected:
- How should a prop name like
onClickbe distinguished from a genuine HTML attribute likeclass, and wired up correctly? - Should a string child be handled differently from an object (element) child?
- Does this need to support recursively building an arbitrarily deep tree of nested children?
Code / implementation expected: Yes — real, direct proof against a real jsdom document: the exact rendered outerHTML, correct nested children and text content, and a real, dispatched click event correctly firing a vnode's own attached handler.