grungnet/src/hooks/usePreventSelect.ts
Mitchell McCaffrey c7b8990a7b Typescript
2021-07-16 16:58:14 +10:00

20 lines
423 B
TypeScript

function usePreventSelect() {
function clearSelection() {
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;