Here's an example in React using a functional component:
const Post = () => {
const handleMouseUp() {
console.log(`Selected text: ${window.getSelection().toString()}`);
}
return (
Text
);
}
As Lyubomir pointed out the window.getSelection() API does the trick!