-
-
Save eiriklv/ef6546404390ba5a68f83416a6261a18 to your computer and use it in GitHub Desktop.
Instance method anti-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
/** | |
* 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