fix: avoid setState in useEffect for sidebar close on navigation

Use ref-based previous pathname check instead of useEffect + setState,
which triggers the react-hooks/set-state-in-effect lint rule.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
0xjjjjjj
2026-03-07 20:18:08 -08:00
parent e85e714076
commit 7a0eb7b24a

View File

@@ -1,6 +1,6 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import type { ReactNode } from "react";
import { usePathname, useRouter } from "next/navigation";
import { Menu, X } from "lucide-react";
@@ -39,9 +39,11 @@ export function DashboardShell({ children }: { children: ReactNode }) {
const displayEmail = profile?.email ?? "";
// Close sidebar on navigation
useEffect(() => {
setSidebarOpen(false);
}, [pathname]);
const prevPathname = useRef(pathname);
if (prevPathname.current !== pathname) {
prevPathname.current = pathname;
if (sidebarOpen) setSidebarOpen(false);
}
useEffect(() => {
if (!isSignedIn || isOnboardingPath) return;