Get React Native Component's Dimensions
In React Native you can use the onLayout
prop along with the nativeEvent's layout to get the dimensions (in pixels) of a rendered component.
const [viewDimensions, setViewDimensions] = useState({height: 0, width: 0})
return (
<View
onLayout={(e) => setViewDimensions(e.nativeEvent.layout)}
/>
)
Now we have an object containging our view's height and width saved as viewDimensions