Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phuochau/9922ee4dc632a3151d2134370802c14a to your computer and use it in GitHub Desktop.
Save phuochau/9922ee4dc632a3151d2134370802c14a to your computer and use it in GitHub Desktop.
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