@fremtind/jkl-react-hooks
Version:
Jøkul react button components
26 lines (25 loc) • 833 B
JavaScript
import { useEffect, useState } from "react";
import { usePreviousValue } from ".";
function useAriaLiveRegion(watch, options) {
const previousValue = usePreviousValue(watch);
const [hasChanged, setHasChanged] = useState(false);
useEffect(() => {
if (Array.isArray(watch) && Array.isArray(previousValue)) {
for (let i = 0; i < watch.length; i++) {
if (watch[i] !== previousValue[i] && !hasChanged) {
setHasChanged(true);
break;
}
}
} else if (previousValue && watch !== previousValue && !hasChanged) {
setHasChanged(true);
}
}, [watch, previousValue, hasChanged]);
return {
"aria-live": hasChanged ? (options == null ? void 0 : options.politeness) || "polite" : void 0
};
}
export {
useAriaLiveRegion
};
//# sourceMappingURL=useAriaLiveRegion.js.map