How to Retrieve Device Info in React Native

Retrieving device information such as the device model, system name, and version can be helpful in a variety of situations. With React Native, you can use the react-native-device-info library to quickly and easily retrieve information about the user’s device.

react native device info

Installing react-native-device-info

First, we need to install the react-native-device-info package. To do so, you can use either the Yarn package manager or npm.

Installing with Yarn

yarn add react-native-device-info

Installing with npm

npm install --save react-native-device-info

Retrieving Device Info in React Native

Once you have installed the react-native-device-info package, you can use the getDeviceInfo method to retrieve the device information.

import DeviceInfo from 'react-native-device-info';

const deviceInfo = DeviceInfo.getDeviceInfo();

This will return an object with the device information.

Various Device Info Properties in React Native

The react-native-device-info package provides various properties that can be used to retrieve specific information about the device. Here are some of the most common ones.

Device Model

You can use the getModel method to retrieve the device model.

import DeviceInfo from 'react-native-device-info';

const deviceModel = DeviceInfo.getModel();

System Name

The getSystemName method can be used to retrieve the system name.

import DeviceInfo from 'react-native-device-info';

const systemName = DeviceInfo.getSystemName();

Version

The getVersion method can be used to retrieve the device version.

import DeviceInfo from 'react-native-device-info';

const version = DeviceInfo.getVersion();

Conclusion

Using the react-native-device-info package, you can quickly and easily retrieve information about the user’s device in React Native. This can be useful for a variety of situations, such as debugging and analytics.