grungnet/src/hooks/usePreventSelect.ts

20 lines
423 B
TypeScript
Raw Permalink Normal View History

function usePreventSelect() {
function clearSelection() {
2021-07-16 06:58:14 +00:00
window?.getSelection()?.removeAllRanges();
// @ts-ignore
document?.selection?.empty();
}
function preventSelect() {
clearSelection();
document.body.classList.add("no-select");
}
function resumeSelect() {
document.body.classList.remove("no-select");
}
return [preventSelect, resumeSelect];
}
export default usePreventSelect;