React creates a virtual dom tree

//dom
//  html       
const React = {
    createElement(tag, attrs, ...children) {
        return {
            tag,
            attrs,
            children
        }
    }
};
const render = (vnode, container) => {
    console.log(vnode)
    //****
    if (typeof vnode === "string") {
        //
        const textNode = document.createTextNode(vnode)
        return container.appendChild(textNode)
    }
    //1.dom   <div></div>
    const dom = document.createElement(vnode.tag);
    console.log(dom)
    //children
    //2.
    vnode.children.forEach(child => {
        return render(child, dom)
    })
    return container.appendChild(dom)
}
const ReactDom = {
    render
}
ReactDom.render(
    //render
    React.createElement("div", null, "hello"),
    //dom
    document.getElementById("app")
)

error, Cannot read property "appendChild" of null

Dec.23,2021

document.getElementById("app")

this should not be on the page

Menu