Last active
December 2, 2015 15:23
-
-
Save Swaagie/3d61aa64cee82b5adf68 to your computer and use it in GitHub Desktop.
Bad React event pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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