1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-17 13:38:37 +01:00

Add return values to SlateReact hooks documentation

This commit is contained in:
Sunny Hirai 2023-04-13 09:07:35 -07:00
parent 5f1baec200
commit d193160fbd

View File

@ -2,30 +2,42 @@
React hooks for Slate editors
### `useFocused`
### `useFocused(): boolean`
Get the current `focused` state of the editor.
### `useReadOnly`
### `useReadOnly(): boolean`
Get the current `readOnly` state of the editor.
### `useSelected`
### `useSelected(): boolean`
Get the current `selected` state of an element.
### `useSlate`
### `useSlate(): ReactEditor`
Get the current editor object from the React context. Re-renders the context whenever changes occur in the editor.
### `useSlateWithV`
### `useSlateWithV(): { editor: ReactEditor, v: number }`
The same as `useSlate()` but includes a version counter which you can use to prevent re-renders.
### `useSlateStatic`
### `useSlateStatic(): ReactEditor`
Get the current editor object from the React context. A version of useSlate that does not re-render the context. Previously called `useEditor`.
### `useSlateSelection`
### `useSlateSelection(): (BaseRange & { placeholder?: string | undefined; onPlaceholderResize?: ((node: HTMLElement | null) => void) | undefined }) | null`
Get the current editor selection from the React context. Only re-renders when the selection changes.
### `useSlateSelector<T>(selector: (editor: Editor): T, equalityFn?: (a: T, b: T) => boolean): T`
Similar to `useSlateSelection` but uses redux style selectors to prevent rerendering on every keystroke.
Bear in mind rerendering can only prevented if the returned value is a value type or for reference types (e.g. objects and arrays) add a custom equality function.
Example:
```typescript
const isSelectionActive = useSlateSelector(editor => Boolean(editor.selection))
```