← Back to Chapters

React Native Device Info

? React Native Device Info

? Quick Overview

React Native Device Info is commonly used to fetch hardware, OS, and application-related details from a user's device such as model, system version, brand, and unique identifiers.

? Key Concepts

  • Accessing device-specific information
  • Platform-aware behavior
  • Native-to-JavaScript bridge usage
  • Environment-based UI logic

? Syntax / Theory

In React Native, device information is typically accessed using a third-party library that bridges native APIs to JavaScript. One of the most widely used libraries is react-native-device-info.

? Code Example(s)

? View Code Example
// Importing DeviceInfo library
import DeviceInfo from 'react-native-device-info';

// Fetch device model
const model = DeviceInfo.getModel();

// Fetch system name
const systemName = DeviceInfo.getSystemName();

console.log(model, systemName);

?️ Live Output / Explanation

Output

The console will log the device model (e.g., iPhone 14, Pixel 7) along with the operating system name such as iOS or Android.

? Interactive Example

Since this is a web browser, we can't access native mobile hardware directly. However, the simulator below mimics how the react-native-device-info API works. Click the buttons to fetch "Device" info!

?️ API Simulator Control Panel:

// Waiting for API calls...
? View Source for Interactive Logic
// How we are simulating these calls in this browser:
const isTablet = window.innerWidth > 768;
const systemName = navigator.platform;

console.log("Is Tablet:", isTablet);
console.log("System:", systemName);

? Use Cases

  • Conditional UI rendering
  • Device-based analytics
  • Debugging device-specific issues
  • Feature toggling by OS or model

✅ Tips & Best Practices

  • Always test on real devices
  • Avoid relying on device info for security
  • Handle permissions carefully
  • Use async APIs where required

? Try It Yourself

  1. Install react-native-device-info in a sample app
  2. Display device brand and version on screen
  3. Change UI color based on OS