concept device in category react native

appears as: device, device
React Native in Action

This is an excerpt from Manning's book React Native in Action.

The final method in the lifecycle is componentDidMount. If you need to do any API calls or AJAX requests to reset the state, this is usually the best place to do so. Finally, the UI is rendered to the device, and you can see the result.

Listing 9.6 Using Dimensions to retrieve the width and height of the device
import React, { Component } from 'react'
import { View, Text, Dimensions, StyleSheet } from 'react-native'    #1  
let styles = {}

const { width, height } = Dimensions.get('window')    #2  
const windowWidth = Dimensions.get('window').width    #3  

const App = () => (
  <View style={styles.container}>    #4  
    <Text>{width}</Text>
    <Text>{height}</Text>
    <Text>{windowWidth}</Text>
  </View>
)

styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  }
})

#1   Imports Dimensions from React Native
#2   Destructures the width and height
#3   Accesses the width object property directly
#4   In the View, render the dimensions that were stored in the variables you retrieved off the Dimensions.get method.

NetInfo is an API that allows you to access data describing whether the device is online or offline. In order to use the NetInfo API on Android, you need to add the required permission to AndroidManifest.xml: