useTextSelection
跟踪用户选中的文字
Usage
实时编辑器
function 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> ); }; render(<Demo/>)
结果
Loading...
API
useTextSelection
Returns
Selection | null
: 选择的文本对象