-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/npm_and_yarn/json5-1.0.2
- Loading branch information
Showing
12 changed files
with
968 additions
and
751 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useState, useEffect } from "react"; | ||
|
||
const QUERY = "(prefers-reduced-motion: no-preference)"; | ||
|
||
export default function usePrefersReducedMotion() { | ||
// Default to prefers animations, since we don't know what the | ||
// user's preference is on the server. | ||
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false); | ||
useEffect(() => { | ||
const mediaQueryList = window.matchMedia(QUERY); | ||
|
||
// Set the true initial value, now that we're on the client: | ||
setPrefersReducedMotion(!window.matchMedia(QUERY).matches); | ||
|
||
// Register our event listener | ||
const listener = (event) => { | ||
setPrefersReducedMotion(!event.matches); | ||
}; | ||
|
||
mediaQueryList.addEventListener("change", listener); | ||
|
||
return () => { | ||
mediaQueryList.removeEventListener("change", listener); | ||
}; | ||
}, []); | ||
|
||
return prefersReducedMotion; | ||
} |
This file contains 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
Oops, something went wrong.