Last active
September 20, 2018 19:06
-
-
Save ajcrites/638e0ce2e4bcc6a0923ae66224318c7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Bad Example | |
| export class ReferenceLiteralComponent extends React.Component { | |
| doSomething() {} | |
| render() { | |
| return ( | |
| <View style={{ backgroundColor: 'red' }}>{ | |
| [1, 2, 3].map( | |
| num => <Text onPress={() => this.doSomething()}>{num}: {new Date()}</Text> | |
| ) | |
| }</View> | |
| ); | |
| } | |
| } |
This file contains hidden or 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
| // Good Example | |
| const styles = StyleSheet.create({ | |
| view: { backgroundColor: 'red' }, | |
| }); | |
| export class NoReferenceLiteralComponent extends React.Component { | |
| // Instance-bound function allows us to still use `this` | |
| // without an additional binding which would create a new function | |
| doSomething = () => {} | |
| numbers = [1, 2, 3]; | |
| date = new Date(); | |
| render() { | |
| return ( | |
| <View style={styles.view}>{ | |
| this.numbers.map( | |
| num => <Text onPress={this.doSomething}>{num}: {this.date}</Text> | |
| ) | |
| }</View> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment