Instantly share code, notes, and snippets.

Embed
What would you like to do?
React components are so fucking stupid, it's unbelievable. 3 months with this library version 15 and the glaring stupidity of the API just keeps coming in waves. Fixing some of this stuff – just for the sake of internal consistency – would have been so simple. The number of hoops you're required to jump through for trivial shit. Ugh.
const mounted = new WeakSet()
export default const unfucker = (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];
}
@zlatnaspirala

This comment has been minimized.

Show comment
Hide comment
@zlatnaspirala

zlatnaspirala Jun 21, 2018

I really glad , i am not alone !

zlatnaspirala commented Jun 21, 2018

I really glad , i am not alone !

@pietrovismara

This comment has been minimized.

Show comment
Hide comment
@pietrovismara

pietrovismara Sep 3, 2018

Fuck this shit

pietrovismara commented Sep 3, 2018

Fuck this shit

@jakubkeller

This comment has been minimized.

Show comment
Hide comment
@jakubkeller

jakubkeller Sep 6, 2018

Vanilla JS, always...

jakubkeller commented Sep 6, 2018

Vanilla JS, always...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment