useTextSelection
Track user text selection based on document.getSelection
Usage
import { useTextSelection } from "@reactuses/core";
const Demo = () => {
const selection = useTextSelection();
return (
<div style={{ padding: 40 }}>
<p>
Select some text here or anywhere on the page and it will be displayed
below
</p>
<div>Selected text: {selection?.toString()}</div>
</div>
);
};
Example
Select some text here or anywhere on the page and it will be displayed below
Selected text:
Type Declarations
export default function useTextSelection(): Selection | null