Skip to content

fix: move mediaQuery inside useEffect to fix missing dependency#1980

Open
lunasilvestre wants to merge 1 commit into
NASA-IMPACT:mainfrom
lunasilvestre:fix/use-prefers-reduced-motion-deps
Open

fix: move mediaQuery inside useEffect to fix missing dependency#1980
lunasilvestre wants to merge 1 commit into
NASA-IMPACT:mainfrom
lunasilvestre:fix/use-prefers-reduced-motion-deps

Conversation

@lunasilvestre
Copy link
Copy Markdown

Related Ticket: N/A

Description of Changes

In useReducedMotion(), the mediaQuery variable was created during render but used inside a useEffect with an empty dependency array, triggering the react-hooks/exhaustive-deps lint warning. This fix moves the MediaQueryList creation inside the effect and uses a lazy useState initializer for the initial value, keeping SSR compatibility.

Notes & Questions About Changes

  • window.matchMedia() returns the same MediaQueryList for the same query string, so the empty dependency array was functionally correct — but the code pattern violated React best practices and the lint rule

Validation / Testing

  • Full test suite passes (161/161)
  • Zero eslint warnings on the modified file (was 1 react-hooks/exhaustive-deps warning before)

The mediaQuery variable was created during render but referenced inside
a useEffect with an empty dependency array, triggering the
react-hooks/exhaustive-deps warning. Move the MediaQueryList creation
inside the effect and use a lazy useState initializer for the initial
value, keeping SSR compatibility.
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 13, 2026

👷 Deploy request for veda-ui pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d974556

@lunasilvestre lunasilvestre marked this pull request as ready for review May 2, 2026 11:35
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