Created
February 25, 2018 09:09
-
-
Save phuochau/9922ee4dc632a3151d2134370802c14a 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
import React, { Component } from 'react' | |
import { | |
View, | |
InteractionManager | |
} from 'react-native' | |
export default class Screen extends Component { | |
constructor (props) { | |
super(props) | |
this.state = { | |
screenLoading: true, | |
contacts: null | |
} | |
} | |
componentDidMount () { | |
InteractionManager.runAfterInteractions(() => { | |
// call API to get data after component was mounted | |
Api.getContacts().then(contacts => { | |
this.setState({ | |
contacts, | |
screenLoading: false | |
}) | |
}) | |
}) | |
} | |
render () { | |
const { screenLoading, contacts } = this.state | |
if (screenLoading) return <LoadingView /> | |
return ( | |
<View> | |
...rendering data | |
</View> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment