useTextSelection
Get the current text selection.
Import
import { useTextSelection } from '@tidbcloud/uikit'Usage
useTextSelection returns the current text selection.
import { useTextSelection } from '@tidbcloud/uikit'
import { Text } from '@tidbcloud/uikit'
function Demo() {
const selection = useTextSelection()
return (
<>
<Text>Select some text on this page</Text>
<Text mt="md">Selected text: {selection?.toString() || 'Nothing selected'}</Text>
</>
)
}Definition
function useTextSelection(): Selection | null