Open blainekasten opened 6 years ago
From an internal discussion with @aweary
brandondail [2:19 PM] I think that if
React.Component
was a native class it would breakblainekasten [2:20 PM] How come? Do you think React will ever do that?
brandondail [2:20 PM] Because you can't invoke a class without using the
new
operator and when you doconstructor.call
it's invoking the class constructor.class Component {}; const ctr = Component.prototype.constructor; ctr.call(this); // Uncaught TypeError: Class constructor Component cannot be invoked without 'new'
I would expect that eventually React will ship native classes (edited)
This is something to think about.
Why is this a bad idea
I'm curious if this is a bad idea to create our own
Component
and have it maintain some internal functionality that extendsReact.Component
.If this isn't a bad idea, I think we can create a really cool state library that makes your application state a first class citizen of React components.
Here is the hack Component over-ride https://github.com/blainekasten/component-extension-idea/blob/master/src/Component.js Here is an implementation https://github.com/blainekasten/component-extension-idea/blob/master/src/App.js#L2-L21
Reasons why I think this is cool