Skip to content

Instantly share code, notes, and snippets.

@eiriklv
Last active September 20, 2018 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eiriklv/ef6546404390ba5a68f83416a6261a18 to your computer and use it in GitHub Desktop.
Save eiriklv/ef6546404390ba5a68f83416a6261a18 to your computer and use it in GitHub Desktop.
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