useScreenOrientation
Tracks the device screen orientation and provides lock and unlock controls.
Loading preview...
The useScreenOrientation hook subscribes to screen.orientation changes via useSyncExternalStore and exposes the current orientation type ('portrait-primary', 'landscape-primary', etc.), rotation angle, and lock / unlock helper methods.
Installation
Usage
Examples
Displaying Current Orientation and Angle
Read type and angle to adapt layouts or prompt users to rotate their device.
Locking Orientation to Landscape
Call lock("landscape") (typically while in fullscreen mode on mobile browsers) and unlock() to release the lock.
API Reference
ScreenOrientationState
Reactive screen orientation state properties.
Property
Specification
typeOrientationType
Current orientation type (e.g.
'portrait-primary', 'landscape-primary').anglenumber
Current orientation angle in degrees (
0, 90, 180, or 270).isSupportedunion
Whether the
screen.orientation API is natively supported.Full Signature
UseScreenOrientationReturn
Screen orientation state and lock/unlock methods returned by the hook.
Property
Specification
lockfunction
Locks the screen orientation to the specified type (if supported by the browser).
Full Signature
Parameters
orientationstringunlockfunction
Unlocks the screen orientation.
Full Signature
typeOrientationType
Current orientation type (e.g.
'portrait-primary', 'landscape-primary').anglenumber
Current orientation angle in degrees (
0, 90, 180, or 270).isSupportedunion
Whether the
screen.orientation API is natively supported.Full Signature