Skip to content

Instantly share code, notes, and snippets.

@eiriklv
Last active Sep 20, 2018
Embed
What would you like to do?
Instance method anti-pattern
/**
* Instance method anti pattern
*/
class MyComponent extends React.Component {
computeThatThing() {
return this.props.a + this.props.b;
}
render() {
return (
<div>{this.computeThatThing()}</div>
)
}
}
/**
* Pure function alternative
*/
function computeThatThing(a, b) {
return a + b;
}
class MyComponent extends React.Component {
render() {
const result = computeThatThing(this.props.a, this.props.b);
return (
<div>{result}</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment