This Node.js package is a collection of React hooks for using the dimensions of the screen, window, or both.
With Node.js installed, simply run the following command to add the package to your project.
npm install react-native-use-dimensions
Check out the examples below or check out the docs.
The package comes with three hooks:
import React from "react";
import { Text } from "react-native";
import useDimensions, {
useScreenDimensions,
useWindowDimensions
} from "react-native-use-dimensions";
const ScreenDimensions = () => {
const { height, width } = useScreenDimensions();
const isLandscape = width > height;
return (
<Text>
{width}x{height}
Orientation: {isLandscape ? "Landscape" : "Portrait"}
</Text>
);
};
const WindowDimensions = () => {
const { height, width } = useWindowDimensions();
const isLandscape = width > height;
return (
<Text>
{width}x{height}
Orientation: {isLandscape ? "Landscape" : "Portrait"}
</Text>
);
};
const BothDimensions = () => {
const { screen, window } = useDimensions();
return (
<Text>
Screen: {screen.width}x{screen.height}
Window: {window.width}x{window.height}
</Text>
);
};
This software is released under the terms of MIT license.
Generated using TypeDoc