Initialisieren
This commit is contained in:
24
hooks/use-prefers-reduced-motion.ts
Normal file
24
hooks/use-prefers-reduced-motion.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
const QUERY = "(prefers-reduced-motion: reduce)";
|
||||
|
||||
function subscribe(callback: () => void) {
|
||||
const mq = window.matchMedia(QUERY);
|
||||
mq.addEventListener("change", callback);
|
||||
return () => mq.removeEventListener("change", callback);
|
||||
}
|
||||
|
||||
function getSnapshot() {
|
||||
return window.matchMedia(QUERY).matches;
|
||||
}
|
||||
|
||||
function getServerSnapshot() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** true, wenn der Nutzer reduzierte Bewegung wünscht (A11y-Gate). */
|
||||
export function usePrefersReducedMotion() {
|
||||
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
||||
}
|
||||
Reference in New Issue
Block a user