React Native Notes

constant Status Bar Height:

import {Constants} from 'expo'
            style={{paddingTop:  Constants.statusBarHeight}}
            

only a few "touchable" components on React Native

Button
            TouchableOpacity
            TouchableHighlight
            TouchableWithoutFeedback
            TouchableNativeFeedback (Android Only)
            

use prevState in setState instead of this.state

this.setState(prevState => ({
                count: prevState.count + 1,
            }))
            

Updates

  1. componentWillReceiveProps(nextProps) use to update state fields that rely on props
  2. shouldComponentUpdate(nextProps, nextState) (this is almost always a premature optimization) compare changed values and decide whether or not you want it to render. if it returns false, the update cycle terminates
  3. render()
  4. componentDidMount(prevProps, prevState) do anything that isn't needed for UI

Unmount

  1. componentwillUnmount remove event listeners invalidate network requests clear timeout or intervals

PropTypes

only runs in development mode!
            makes props typed (vs untyped)
            static propTypes = {
                count: Proptypes.number.isRequired,
            }