fix(eslint): resolve setState-in-effect errors in dashboard components (#1362)

- LanguageSwitcher: remove mounted state + useLayoutEffect pattern
  Portal renders directly based on open state (SSR-safe without client check)
- UsageStats: replace stats-null check with isInitialLoad ref to avoid
  setState in effect body (cascading render issue)
This commit is contained in:
OKWN
2026-05-23 09:24:35 +07:00
committed by GitHub
parent 7bc97eae7b
commit d29b19bc27
2 changed files with 11 additions and 7 deletions
+3 -4
View File
@@ -1,6 +1,6 @@
"use client";
import { useState, useEffect } from "react";
import { useState, useLayoutEffect } from "react";
import { createPortal } from "react-dom";
import { useRouter, usePathname } from "next/navigation";
import { Globe, X } from "lucide-react";
@@ -15,12 +15,11 @@ function extractLangFromPath(pathname) {
export default function LanguageSwitcher({ currentLang }) {
const [open, setOpen] = useState(false);
const [mounted, setMounted] = useState(false);
const router = useRouter();
const pathname = usePathname();
const current = getLanguage(currentLang);
useEffect(() => {
useLayoutEffect(() => {
setMounted(true);
}, []);
@@ -91,7 +90,7 @@ export default function LanguageSwitcher({ currentLang }) {
<span className="sm:hidden">{current.flag}</span>
</button>
{mounted && open && createPortal(modal, document.body)}
{open && createPortal(modal, document.body)}
</>
);
}