Dimensions API

React Native 6 min min read Updated: Jul 26, 2026 Intermediate
Dimensions API
Intermediate Topic 25 of 30

Dimensions API

The Dimensions API provides access to the current device screen and window dimensions, allowing developers to build layouts that adapt based on the exact size of the user’s device.

Getting Screen Dimensions

javascript import { Dimensions } from 'react-native'; const { width, height } = Dimensions.get('window');

Window vs Screen

Dimensions.get accepts either "window" or "screen" as an argument. "window" represents the visible application area, while "screen" represents the full physical device screen, which can differ slightly on Android.

Using Dimensions for Responsive Sizing

javascript const cardWidth = width * 0.9;

Listening for Dimension Changes

Since screen dimensions can change due to device rotation, it is important to listen for changes using the Dimensions event listener instead of only reading the value once.

javascript import { useState, useEffect } from 'react'; import { Dimensions } from 'react-native'; function useScreenWidth() { const [width, setWidth] = useState(Dimensions.get('window').width); useEffect(() => { const subscription = Dimensions.addEventListener('change', ({ window }) => { setWidth(window.width); }); return () => subscription.remove(); }, []); return width; }

Using the useWindowDimensions Hook

React Native also provides a useWindowDimensions hook, which automatically updates and re-renders your component whenever the screen size changes, offering a simpler alternative to manual event listeners.

javascript import { useWindowDimensions } from 'react-native'; function App() { const { width, height } = useWindowDimensions(); return {width} x {height}; }

Conclusion

The Dimensions API, along with the useWindowDimensions hook, gives developers the tools needed to build layouts that respond dynamically to different screen sizes and orientation changes in React Native.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators