useOrientation

Track the device orientation.

https://www.shaktools.com/shak-hooks
Sensor

API Reference

Installation

terminal
pnpm add @shak-hooks/usehooks
import.ts
import { useOrientation } from "@shak-hooks/usehooks";
Source: packages/react/src/useOrientation.ts

Signature

signature.ts
export function useOrientation(): OrientationState

Parameters

No parameters.

Returns

OrientationState

Exported Types

types.ts
1export interface OrientationState {
2 angle: number;
3 type: string;
4}

Implementation

use-orientation.ts
1import { useEffect, useState } from "react";
2
3interface OrientationState {
4 angle: number;
5 type: string;
6}
7
8export function useOrientation(): OrientationState {
9 const [orientation, setOrientation] = useState<OrientationState>({
10 angle: 0,
11 type: "landscape-primary",
12 });
13
14 useEffect(() => {
15 const handleChange = () => {
16 const { angle, type } = window.screen.orientation;
17 setOrientation({
18 angle,
19 type,
20 });
21 };
22
23 const handleResize = () => {
24 handleChange();
25 };
26
27 window.addEventListener("orientationchange", handleChange);
28 window.addEventListener("resize", handleResize);
29 handleChange();
30
31 return () => {
32 window.removeEventListener("orientationchange", handleChange);
33 window.removeEventListener("resize", handleResize);
34 };
35 }, []);
36
37 return orientation;
38}

Advertisement

Google Ads

Usage

example.tsx
1import { useOrientation } from "@shak-hooks/usehooks";
2
3const result = useOrientation();
4// result: OrientationState
5// Use values directly (React state).

Let‘s do great work together

Empowering creators with free, high-performance AI, SEO, and developer tools. Join thousands of users optimizing their workflow with Shak-Tools.

Tools10+ Free
UsersGlobal

Stay in the loop

Join our newsletter for the latest AI tools and updates.

ShakTools
© 2025 Shaktools. All Rights Reserved.Privacy Policy