-
-
Save barneycarroll/50295a5f36a45dd5bc772f5236bf5bbb to your computer and use it in GitHub Desktop.
const mounted = new WeakSet() | |
export default (component, displayName = component.displayName || component.name || 'React.Component') => { | |
const host = { | |
[displayName] : class extends React.Component { | |
constructor(){ | |
this.state = {} | |
component.apply(this, arguments) | |
} | |
setState(partial, callback){ | |
this.state = Object.assign({}, this.state, typeof partial === 'function' ? partial(this.state, this.props) : partial) | |
callback() | |
} | |
componentDidMount(){ | |
this.setState = React.Component.prototype.setState | |
if(component.prototype.componentDidMount) | |
return component.prototype.componentDidMount.apply(this, arguments) | |
} | |
render(){ | |
if(!component.prototype.render) | |
return this.props.children || [] | |
const output = component.prototype.render.apply(this, arguments) | |
if(this.props.key && output.key === null) | |
output.key = key | |
} | |
} | |
} | |
return host[displayName]; | |
} |
feel better now
I swear people sit at home and find ways to make things more complex than they need to be. I've been looking for away to access a DOM element from within two functional components for days! When this would've been done in a matter of seconds using document.getElementById() or document.querySelector() in JS. One article advising to use Ref and another saying it's bad practice to use Ref when accessing DOM elements. Which is it F*%k the right way or wrong way?!?!?!?
React is pure trash. Use svelte
React is the best evidence I have for the existence of evil
Hello, dear people who once commented this gist.
This is a friendly reminder to touch grass and drink water.
Don't touch grass, it's full of allergens.
After working with React for 5 months my conclusion is:
React to the frontend is like PHP to the backend.
Fuck Vue.JS
https://www.google.com/search?q=WHY+THIS+FUCKING+COMPONENT+FUCKING+RENDERS&oq=WHY+THIS+FUCKING+COMPONENT+FUCKING+RENDERS&aqs=chrome..69i57.7659j0j7&sourceid=chrome&ie=UTF-8