SelectionChangeEvent Handler
Unanswered
Atlantic mackerel posted this in #help-forum
Atlantic mackerelOP
hey guys, I wanna showing some menu (like notion) if selected text
But the below code doesn't work at all
how can I detect selectionchange on nextjs?
But the below code doesn't work at all
const [isSelected, setIsSelected] = useState<boolean>();
useEffect(() => {
document.addEventListener("selectionchange", () => {
const activeSelection = document.getSelection();
let selectedText = activeSelection?.toString();
setIsSelected(selectedText?.length == 0);
console.log("selectedText", selectedText?.length)
})
}, []);
how can I detect selectionchange on nextjs?