Skip to content

Commit 75dfd1d

Browse files
fix: revert and update useLocaleDirection usage
1 parent a0c3e92 commit 75dfd1d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/components/ThemeProvider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { ThemeProviderProps } from "next-themes/dist/types"
33

44
import { COLOR_MODE_STORAGE_KEY } from "@/lib/constants"
55

6+
import { useLocaleDirection } from "@/hooks/useLocaleDirection"
7+
68
/**
79
* Primary theming wrapper for use with color mode. Uses the theme provider
810
* from `next-themes`.
@@ -11,6 +13,8 @@ import { COLOR_MODE_STORAGE_KEY } from "@/lib/constants"
1113
* primary decorator to Storybook.
1214
*/
1315
const ThemeProvider = ({ children }: Pick<ThemeProviderProps, "children">) => {
16+
useLocaleDirection()
17+
1418
return (
1519
<NextThemesProvider
1620
attribute="data-theme"

src/hooks/useLocaleDirection.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from "react"
1+
import { useEffect } from "react"
22
import { useRouter } from "next/router"
33

44
import { Lang } from "@/lib/types"
@@ -9,15 +9,11 @@ import { isLangRightToLeft } from "@/lib/utils/translations"
99
* Custom hook that sets the DOM direction based on the locale,
1010
* responding to changes in the locale without requiring refresh.
1111
*/
12-
export const useLocaleDirection = (): string => {
13-
const [direction, setDirection] = useState<"ltr" | "rtl">("ltr")
12+
export const useLocaleDirection = () => {
1413
const { locale } = useRouter()
1514

1615
useEffect(() => {
1716
const dir = isLangRightToLeft(locale as Lang) ? "rtl" : "ltr"
1817
document.documentElement.setAttribute("dir", dir)
19-
setDirection(dir)
2018
}, [locale])
21-
22-
return direction
2319
}

0 commit comments

Comments
 (0)