Categories
JavaScript Answers React Native Answers

How to determine if a device is iPhone or iPad with React Native?

Spread the love

Sometimes, we want to determine if a device is iPhone or iPad with React Native

In this article, we’ll look at how to determine if a device is iPhone or iPad with React Native.

How to determine if a device is iPhone or iPad with React Native?

To determine if a device is iPhone or iPad with React Native, we can use the Platform.isPad property.

If it’s true, then it’s an iPad. If it’s false, it’s an iPhone.

Otherwise, it’s undefined.

For instance, we write:

import * as React from 'react';
import { FlatList, Text, View } from 'react-native';
import { Platform } from 'react-native';

export default function App() {
  console.log(Platform.isPad);

  return <View style={{ height: 300 }}></View>;
}

to log the value of Platform.isPad.

If it’s true, then it’s an iPad.

Conclusion

To determine if a device is iPhone or iPad with React Native, we can use the Platform.isPad property.

If it’s true, then it’s an iPad. If it’s false, it’s an iPhone.

Otherwise, it’s undefined.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *