Skip to content

Instantly share code, notes, and snippets.

@Swaagie
Last active December 2, 2015 15:23
Show Gist options
  • Save Swaagie/3d61aa64cee82b5adf68 to your computer and use it in GitHub Desktop.
Save Swaagie/3d61aa64cee82b5adf68 to your computer and use it in GitHub Desktop.
Bad React event pattern
import React, { Component } from 'react';
class Eventer extends React.Component {
constructor(props) {
super(props);
this.state = {
something: 'test'
};
}
get trigger() {
return (event) => {
this.stateChanger(function stateChanged() {
console.log(event); // this will be an `nulled` event { preventDefault: null, stopPropagation: null, etc }
});
};
}
stateChanger(done) {
this.setState({
something: 'changed'
}, done);
}
render() {
return <a onClick={this.trigger}>{this.state.something}</a>;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment