DEV Community

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

Collapse
 
alexandrzavalii profile image
Alex Zavalii

Nice! Would like to see the comparison with functional component.

Collapse
 
carlmungazi profile image
Carl Mungazi

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);
  }