loading...

re: Turning `class App extends React.Component` into a coding lesson VIEW POST

FULL DISCUSSION
 

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

 

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

code of conduct - report abuse