VOOZH about

URL: https://www.geeksforgeeks.org/react-native/how-to-get-window-width-and-height-in-react-native/

⇱ Getting Window Width and Height In React Native - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Getting Window Width and Height In React Native

Last Updated : 19 Feb, 2026

In React Native, obtaining the screen width and height is essential for creating responsive and adaptive user interfaces. It helps developers design layouts that adjust properly across different devices and screen orientations.

  • Screen dimensions allow developers to create responsive layouts that fit various device sizes.
  • They help ensure a consistent user experience across different screen resolutions and orientations.
  • React Native provides different approaches, such as using the Dimensions API and useWindowDimensions hook, to access screen width and height.

Step-by-Step Implementation

Step 1: Create a React Native Project

Now, create a project with the following command.

npx create-expo-app app-name --template

Note: Replace the app-name with your app name for example : react-native-demo-app

Next, you might be asked to choose a template. Select one based on your preference as shown in the image below. I am selecting the blank template because it will generate a minimal app, as clean as an empty canvas in JavaScript.

👁 Image

It completes the project creation and displays a message: "Your Project is ready!" as shown in the image below.

👁 Image

Now go into your project folder, i.e., react-native-demo

cd app-name

Project Structure

👁 Image

Step 2: Run  Application

Start the server by using the following command.

npx expo start

Then, the application will display a QR code.

1. For the Android users,

  • For the Android Emulator, press "a" as mentioned in the image below.
  • For the Physical Device, download the "Expo Go" app from the Play Store. Open the app, and you will see a button labeled "Scan QR Code." Click that button and scan the QR code; it will automatically build the Android app on your device.

2. For iOS users, simply scan the QR code using the Camera app.

3. If you're using a web browser, it will provide a local host link that you can use as mentioned in the image below.

👁 Image

Step 3: Start Coding

Approach 1: Using the Dimensions Module

In this approach, the Dime­nsions module is utilized to retrie­ve the scree­n width and height. By invoking Dimensions.get('window'), the­ dimensions are accesse­d and displayed using the Text compone­nt.

Output:

👁 Screenshot-2026-02-19-155055


Approach 2: Using useWindowDimensions

In this approach, we'll use the useWindow­Dimensions hook to effort­lessly access the width and height of the screen.

Example: The code defines a React Native component named 'App' that showcases the dimen­sions of the device screen. It imports necessary compo­nents from 'react-native' while utilizing the useWindow­Dimensions hook to obtain both the width and height of the scree­n.

Output:

👁 Using_useWindowDimensions
Comment
Article Tags:

Explore