You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Implement experimental chunking optimization (disabled by default, see https://docs.slatejs.org/walkthroughs/09-performance).
6
+
- Add `useElement` and `useElementIf` hooks to get the current element.
7
+
-**BREAKING CHANGE:** Decorations are no longer recomputed when a node's parent re-renders, only when the node itself re-renders or when the `decorate` function is changed.
8
+
- Ensure that `decorate` is a pure function of the node passed into it. Depending on the node's parent may result in decorations not being recomputed when you expect them to be.
9
+
- If this change impacts you, consider changing your `decorate` function to work on the node's parent instead.
10
+
- For example, if your `decorate` function decorates a `code-line` based on the parent `code-block`'s language, decorate the `code-block` instead.
11
+
- This is unlikely to result in any performance detriment, since in previous versions of `slate-react`, the decorations of all siblings were recomputed when one sibling was modified.
12
+
- Increase minimum `slate-dom` version to `0.116.0`.
13
+
- Deprecate the `useSlateWithV` hook
14
+
- PERF: Use subscribable pattern for `useSlate`, `useSelected` and decorations to reduce re-renders.
Copy file name to clipboardExpand all lines: docs/libraries/slate-react/hooks.md
+14-22Lines changed: 14 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
# Slate React Hooks
2
2
3
-
-[Check hooks](hooks.md#check-hooks)
4
-
-[Editor hooks](hooks.md#editor-hooks)
5
-
-[Selection hooks](hooks.md#selection-hooks)
6
-
7
-
### Check hooks
8
-
9
-
React hooks for Slate editors
10
-
11
3
#### `useComposing(): boolean`
12
4
13
5
Get the current `composing` state of the editor. It deals with `compositionstart`, `compositionupdate`, `compositionend` events.
14
6
15
7
Composition events are triggered by typing (composing) with a language that uses a composition character (e.g. Chinese, Japanese, Korean, etc.) [example](https://en.wikipedia.org/wiki/Input_method#/media/File:Typing_%EC%9E%88%EC%8A%B5%EB%8B%88%EB%8B%A4_in_Dubeolsik_keyboard_layout.gif).
16
8
9
+
#### `useElement(): Element`
10
+
11
+
Get the current element object. Re-renders whenever the element or any of its descendants changes.
12
+
13
+
#### `useElementIf(): Element | null`
14
+
15
+
The same as `useElement()` but returns `null` instead of throwing an error when not inside an element.
16
+
17
17
#### `useFocused(): boolean`
18
18
19
19
Get the current `focused` state of the editor.
@@ -24,35 +24,27 @@ Get the current `readOnly` state of the editor.
24
24
25
25
#### `useSelected(): boolean`
26
26
27
-
Get the current `selected` state of an element.
28
-
29
-
### Editor hooks
27
+
Get the current `selected` state of an element. An element is selected if `editor.selection` exists and overlaps any part of the element.
30
28
31
29
#### `useSlate(): Editor`
32
30
33
-
Get the current editor object from the React context. Re-renders the context whenever changes occur in the editor.
34
-
35
-
#### `useSlateWithV(): { editor: Editor, v: number }`
36
-
37
-
The same as `useSlate()` but includes a version counter which you can use to prevent re-renders.
31
+
Get the current editor object. Re-renders whenever changes occur in the editor.
38
32
39
33
#### `useSlateStatic(): Editor`
40
34
41
35
Get the current editor object from the React context. A version of useSlate that does not re-render the context. Previously called `useEditor`.
Similar to `useSlateSelection` but uses redux style selectors to prevent rerendering on every keystroke.
43
+
Use redux style selectors to prevent re-rendering on every keystroke.
52
44
53
-
Returns a subset of the full selection value based on the `selector`.
45
+
Bear in mind re-rendering 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.
54
46
55
-
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.
47
+
If `selector` is memoized using `useCallback`, then it will only be called when it or the editor state changes. Otherwise, `selector` will be called every time the component renders.
0 commit comments