v6.0.35

use-text-selection

Get current selected text on the page
Import

Usage

use-text-selection hook returns current text selection:

Select some text here or anywhere on the page and it will be displayed below
Selected text:
import { useTextSelection } from '@asuikit/hooks';
function Demo() {
const selection = useTextSelection();
return (
<>
<div>Select some text here or anywhere on the page and it will be displayed below</div>
<div>Selected text: {selection?.toString()}</div>
</>
);
}

Definition

function useTextSelection(): Selection | null;