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