React hooks for Slate editors
Get the current composing
state of the editor. It deals with compositionstart
, compositionupdate
, compositionend
events.
Composition events are triggered by typing (composing) with a language that uses a composition character (e.g. Chinese, Japanese, Korean, etc.) example.
Get the current focused
state of the editor.
Get the current readOnly
state of the editor.
Get the current selected
state of an element.
Get the current editor object from the React context. Re-renders the context whenever changes occur in the editor.
The same as useSlate()
but includes a version counter which you can use to prevent re-renders.
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
Get the current editor selection from the React context. Only re-renders when the selection changes.
Similar to useSlateSelection
but uses redux style selectors to prevent rerendering on every keystroke.
Returns a subset of the full selection value based on the selector
.
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 for the equalityFn
argument.
Example:
const isSelectionActive = useSlateSelector(editor => Boolean(editor.selection))