UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

1 lines 1.2 kB
{"version":3,"file":"use-text-selection.cjs","names":["useForceUpdate"],"sources":["../../src/use-text-selection/use-text-selection.ts"],"sourcesContent":["import { useEffect, useEffectEvent, useState } from 'react';\nimport { useForceUpdate } from '../use-force-update/use-force-update';\n\nexport function useTextSelection(): Selection | null {\n const forceUpdate = useForceUpdate();\n const [selection, setSelection] = useState<Selection | null>(null);\n\n const handleSelectionChange = useEffectEvent(() => {\n setSelection(document.getSelection());\n forceUpdate();\n });\n\n useEffect(() => {\n setSelection(document.getSelection());\n document.addEventListener('selectionchange', handleSelectionChange);\n return () => document.removeEventListener('selectionchange', handleSelectionChange);\n }, []);\n\n return selection;\n}\n"],"mappings":";;;;AAGA,SAAgB,mBAAqC;CACnD,MAAM,cAAcA,yBAAAA,gBAAgB;CACpC,MAAM,CAAC,WAAW,iBAAA,GAAA,MAAA,UAA2C,KAAK;CAElE,MAAM,yBAAA,GAAA,MAAA,sBAA6C;AACjD,eAAa,SAAS,cAAc,CAAC;AACrC,eAAa;GACb;AAEF,EAAA,GAAA,MAAA,iBAAgB;AACd,eAAa,SAAS,cAAc,CAAC;AACrC,WAAS,iBAAiB,mBAAmB,sBAAsB;AACnE,eAAa,SAAS,oBAAoB,mBAAmB,sBAAsB;IAClF,EAAE,CAAC;AAEN,QAAO"}