Skip to content
Playground

useDirection

Read the nearest left-to-right or right-to-left direction context.

useDirection returns the reading direction supplied by the nearest DirectionProvider. Use it when custom interaction behavior must distinguish logical start from logical end.

TSX
import { useDirection } from "@zentara-co/zenos-ui";
TSX
"use client"; import { useDirection } from "@zentara-co/zenos-ui"; export function DirectionStatus() {  const direction = useDirection();   return <span>Current direction: {direction}</span>;}

The return value is "ltr" | "rtl". Without a provider, the hook returns "ltr".

Keep the provider direction and the native DOM dir attribute synchronized. The provider supplies component behavior; dir controls browser layout and text flow.

TSX
import { DirectionProvider, useDirection } from "@zentara-co/zenos-ui"; function Toolbar() {  const direction = useDirection();  const previousKey = direction === "rtl" ? "ArrowRight" : "ArrowLeft";   return <p>Previous item key: {previousKey}</p>;} export function ArabicWorkspace() {  return (    <section lang="ar" dir="rtl">      <DirectionProvider direction="rtl">        <Toolbar />      </DirectionProvider>    </section>  );}

Use useDirection for behavior that cannot be expressed through CSS, including direction-aware arrow-key handling, carousel traversal, or application-owned positioning logic.

For layout, prefer logical CSS properties and utilities such as start, end, ms, me, ps, and pe. CSS automatically follows the nearest DOM direction and does not require a React render.

The hook reads React context and does not access browser APIs. It returns the provider value during server rendering, or ltr when no provider exists, so the server and client remain deterministic when the provider tree is the same.

See Direction for provider setup, scoped direction, and portal guidance. See the RTL foundation guide for layout, icon, content, and testing recommendations.