Skip to content

Revert "Deploy StepFi-Web to Vercel"#35

Open
EmeditWeb wants to merge 1 commit into
mainfrom
revert-33-main
Open

Revert "Deploy StepFi-Web to Vercel"#35
EmeditWeb wants to merge 1 commit into
mainfrom
revert-33-main

Conversation

@EmeditWeb

Copy link
Copy Markdown
Member

@EneGab please work on the build fail

Fix the ESLint error in src/components/layout/Navbar.tsx.

The error is on line 28:
react-hooks/set-state-in-effect
Calling setState synchronously within an effect is not allowed.

The current code:
useEffect(() => {
setMobileOpen(false)
}, [pathname])

Fix by wrapping the setState call in a cleanup or using
a ref to avoid the synchronous setState inside the effect.

The correct pattern is to check if pathname changed
using a ref instead of calling setState inside the effect:

import { useEffect, useRef } from 'react'

const prevPathnameRef = useRef(pathname)

useEffect(() => {
if (prevPathnameRef.current !== pathname) {
prevPathnameRef.current = pathname
setMobileOpen(false)
}
}, [pathname])

OR the simpler approach that also satisfies the linter:

Remove the useEffect entirely and instead close the
menu by passing an onClick handler to each nav Link:

setMobileOpen(false)} ... >

This is cleaner because it only closes the menu when
the user actually clicks a link, not on every pathname
change, which is the more correct behavior anyway.

After fixing:
npm run lint 2>&1 | tail -5
npm run build 2>&1 | tail -5
Both must exit 0.

Commit and push to your branch:
git add src/components/layout/Navbar.tsx
git commit -m "fix: remove setState in effect for mobile menu close"
git push origin [branch-name]

Report: lint and build output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant