use-text-selection

Returns current selected text on the page

Import

Usage

use-text-selection returns current text selection:

Select some text here or anywhere on the page and it will be displayed below
Selected text:
import { useTextSelection } from '@mantine/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;