File tree Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,26 @@ function BlockNoteViewComponent<
152
152
153
153
// We set defaultUIProps and editorProps on a different context, the BlockNoteViewContext.
154
154
// This BlockNoteViewContext is used to render the editor and the default UI.
155
- const defaultUIProps = {
155
+ const blockNoteViewContextValue = useMemo ( ( ) => {
156
+ return {
157
+ editorProps : {
158
+ autoFocus,
159
+ contentEditableProps,
160
+ } ,
161
+ defaultUIProps : {
162
+ formattingToolbar,
163
+ linkToolbar,
164
+ slashMenu,
165
+ emojiPicker,
166
+ sideMenu,
167
+ filePanel,
168
+ tableHandles,
169
+ comments,
170
+ } ,
171
+ } ;
172
+ } , [
173
+ autoFocus ,
174
+ contentEditableProps ,
156
175
formattingToolbar ,
157
176
linkToolbar ,
158
177
slashMenu ,
@@ -161,21 +180,11 @@ function BlockNoteViewComponent<
161
180
filePanel ,
162
181
tableHandles ,
163
182
comments ,
164
- } ;
165
-
166
- const editorProps = {
167
- autoFocus,
168
- contentEditableProps,
169
- } ;
183
+ ] ) ;
170
184
171
185
return (
172
186
< BlockNoteContext . Provider value = { blockNoteContext } >
173
- < BlockNoteViewContext . Provider
174
- value = { {
175
- editorProps,
176
- defaultUIProps,
177
- } }
178
- >
187
+ < BlockNoteViewContext . Provider value = { blockNoteViewContextValue } >
179
188
< ElementRenderer ref = { setElementRenderer } />
180
189
< BlockNoteViewContainer
181
190
className = { className }
Original file line number Diff line number Diff line change 1
1
import { BlockNoteEditor , StyleSchema } from "@blocknote/core" ;
2
2
3
- import { useState } from "react" ;
3
+ import { useCallback , useState } from "react" ;
4
4
import { useBlockNoteContext } from "../editor/BlockNoteContext.js" ;
5
5
import { useEditorChange } from "./useEditorChange.js" ;
6
6
import { useEditorSelectionChange } from "./useEditorSelectionChange.js" ;
@@ -23,15 +23,15 @@ export function useActiveStyles<T extends StyleSchema>(
23
23
24
24
const [ styles , setStyles ] = useState ( ( ) => e . getActiveStyles ( ) ) ;
25
25
26
- // Updates state on editor content change.
27
- useEditorChange ( ( ) => {
26
+ const updateStyles = useCallback ( ( ) => {
28
27
setStyles ( e . getActiveStyles ( ) ) ;
29
- } , e ) ;
28
+ } , [ e ] ) ;
29
+
30
+ // Updates state on editor content change.
31
+ useEditorChange ( updateStyles , e ) ;
30
32
31
33
// Updates state on selection change.
32
- useEditorSelectionChange ( ( ) => {
33
- setStyles ( e . getActiveStyles ( ) ) ;
34
- } , e ) ;
34
+ useEditorSelectionChange ( updateStyles , e ) ;
35
35
36
36
return styles ;
37
37
}
Original file line number Diff line number Diff line change 5
5
InlineContentSchema ,
6
6
StyleSchema ,
7
7
} from "@blocknote/core" ;
8
- import { useState } from "react" ;
8
+ import { useCallback , useState } from "react" ;
9
9
import { useBlockNoteContext } from "../editor/BlockNoteContext.js" ;
10
10
import { useEditorContentOrSelectionChange } from "./useEditorContentOrSelectionChange.js" ;
11
11
@@ -31,13 +31,15 @@ export function useSelectedBlocks<
31
31
Block < BSchema , ISchema , SSchema > [ ]
32
32
> ( ( ) => e . getSelection ( ) ?. blocks || [ e . getTextCursorPosition ( ) . block ] ) ;
33
33
34
- useEditorContentOrSelectionChange (
34
+ const updateSelectedBlocks = useCallback (
35
35
( ) =>
36
36
setSelectedBlocks (
37
37
e . getSelection ( ) ?. blocks || [ e . getTextCursorPosition ( ) . block ] ,
38
38
) ,
39
- e ,
39
+ [ e ] ,
40
40
) ;
41
41
42
+ useEditorContentOrSelectionChange ( updateSelectedBlocks , e ) ;
43
+
42
44
return selectedBlocks ;
43
45
}
You can’t perform that action at this time.
0 commit comments