import { useState } from "react" ; import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect" ; export function useTextDirection ( ref ) { const [ direction , setDirection ] = useState < string > ( ) ; useIsomorphicLayoutEffect ( ( ) => { const computedStyle = window . getComputedStyle ( ref . current ! ) ; setDirection ( computedStyle . direction ) ; } , [ ref ] ) ; return direction as "ltr" | "rtl" | undefined ; }