fix: move mediaQuery inside useEffect to fix missing dependency#1980
Open
lunasilvestre wants to merge 1 commit into
Open
fix: move mediaQuery inside useEffect to fix missing dependency#1980lunasilvestre wants to merge 1 commit into
lunasilvestre wants to merge 1 commit into
Conversation
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.
👷 Deploy request for veda-ui pending review.Visit the deploys page to approve it
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Ticket: N/A
Description of Changes
In
useReducedMotion(), themediaQueryvariable was created during render but used inside auseEffectwith an empty dependency array, triggering thereact-hooks/exhaustive-depslint warning. This fix moves theMediaQueryListcreation inside the effect and uses a lazyuseStateinitializer for the initial value, keeping SSR compatibility.Notes & Questions About Changes
window.matchMedia()returns the sameMediaQueryListfor the same query string, so the empty dependency array was functionally correct — but the code pattern violated React best practices and the lint ruleValidation / Testing
react-hooks/exhaustive-depswarning before)