DEV Community

loading...

Discussion on: Turning `class App extends React.Component` into a coding lesson

Collapse
carlmungazi profile image
Carl Mungazi Author

Yes, I never looked at that but just this week I've been adding components to the virtual dom framework I am building. This is how I am handling the components and I imagine React probably does something similar (with more complexity, of course)

// you write your component
function Comp() {
  // ... do stuff here
}

// the framework handles it like so
if (typeof vNode.type === 'function') {
    const Component = vNode.type;
     // ... set the props here
    // ... create update function which is similar to setState

    const renderedComponent = Component(props, updateFn);

    return renderElement(renderedComponent);
  }

Forem Open with the Forem app