Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Easy Way to Improve ReactNative

Easy Way to Improve ReactNative

5 easy way to improve ReactNative project

Sergio Utama

July 12, 2018
Tweet

More Decks by Sergio Utama

Other Decks in Programming

Transcript

  1. Why — Easier to navigate and maintain — Mental image

    how code should be structured @sergioutama
  2. How ~ components for reusable globaly ~ Split based on

    screen OR module ~ each screen has its component @sergioutama
  3. Arrow function ( () => {}) is a necessary evil

    of js world. It make easy to ignore this @sergioutama
  4. However, arrow function actually assigning a new value. Calling it

    within render() function will give significant impact on your app performance @sergioutama
  5. Understand how React lifecycle and avoid unecessary render by extending

    PureComponent or implementing shouldComponentUpdate. Be!er: fully utilize the whole lifecycle functions. @sergioutama
  6. Keep your component small. It's not a dick measuring contents

    If more than 6 elements, move it to a component @sergioutama
  7. const modalClosed = ()=>{} const LoadingOverlay = (props) => {

    const { loading, message, ...attributes } = props; const defaultMessage = message || ''; return ( <Modal transparent animationType={'none'} visible={loading} onRequestClose={modalClosed} > <View style={styles.modalBackground}> <View style={styles.activityIndicatorWrapper}> <ActivityIndicator animating={loading} /> <Text style={styles.loadingText}>{defaultMessage}</Text> </View> </View> </Modal> ); }; @sergioutama
  8. const modalClose = () => {}; export default class LoadingOverlay

    extends React.Component<Props> { render() { const { loading, message, style } = this.props; const defaultMessage = message || ""; return ( <Modal transparent animationType={"none"} visible={loading} onRequestClose={modalClose} > <View style={styles.modalBackground}> <View style={styles.activityIndicatorWrapper}> <ActivityIndicator animating={loading} /> <Text style={styles.loadingText}>{defaultMessage}</Text> </View> </View> </Modal> ); } } @sergioutama
  9. Why Similar but not the same It makes sense on

    web or React to use functional stateless component It doesn't make sense on ReactNative Component make it easier to debug view hierarchy @sergioutama