1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-17 21:49:20 +01:00

Organize hooks documentation and add subheadings

This commit is contained in:
Sunny Hirai 2023-04-13 09:10:12 -07:00
parent d193160fbd
commit c6b7db2e13

View File

@ -1,36 +1,46 @@
# Slate React Hooks
- [Check hooks](hooks.md#check-hooks)
- [Editor hooks](hooks.md#editor-hooks)
- [Selection hooks](hooks.md#selection-hooks)
### Check hooks
React hooks for Slate editors
### `useFocused(): boolean`
#### `useFocused(): boolean`
Get the current `focused` state of the editor.
### `useReadOnly(): boolean`
#### `useReadOnly(): boolean`
Get the current `readOnly` state of the editor.
### `useSelected(): boolean`
#### `useSelected(): boolean`
Get the current `selected` state of an element.
### `useSlate(): ReactEditor`
### Editor hooks
#### `useSlate(): ReactEditor`
Get the current editor object from the React context. Re-renders the context whenever changes occur in the editor.
### `useSlateWithV(): { editor: ReactEditor, v: number }`
#### `useSlateWithV(): { editor: ReactEditor, v: number }`
The same as `useSlate()` but includes a version counter which you can use to prevent re-renders.
### `useSlateStatic(): ReactEditor`
#### `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(): (BaseRange & { placeholder?: string | undefined; onPlaceholderResize?: ((node: HTMLElement | null) => void) | undefined }) | null`
### Selection hooks
#### `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`
#### `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.