@@ -32,6 +32,7 @@ import {
32
32
useReducer ,
33
33
useRef ,
34
34
useState ,
35
+ useCallback ,
35
36
} from 'preact/hooks' ;
36
37
import { route } from 'preact-router' ;
37
38
import * as schema from '../../../core/schema.js' ;
@@ -106,22 +107,24 @@ export function DocEditor(props: DocEditorProps) {
106
107
const collection = useCollectionSchema ( props . collection . id ) ;
107
108
const draft = props . draft ;
108
109
const { controller, saveState, data} = draft ;
109
- const ref = useRef < HTMLDivElement > ( null ) ;
110
110
const [ deeplink , setDeeplink ] = useState ( '' ) ;
111
111
const [ clipboardValue , setClipboardValue ] = useState ( null ) ;
112
112
const loading = collection . loading || draft . loading ;
113
113
const fields = collection . schema ?. fields || [ ] ;
114
114
115
- function goBack ( ) {
115
+ const goBack = useCallback ( ( ) => {
116
116
const collectionId = props . docId . split ( '/' ) [ 0 ] ;
117
117
route ( `/cms/content/${ collectionId } ` ) ;
118
- }
118
+ } , [ props . docId ] ) ;
119
119
120
- function onDocAction ( event : DocActionEvent ) {
121
- if ( event . action === 'delete' ) {
122
- goBack ( ) ;
123
- }
124
- }
120
+ const onDocAction = useCallback (
121
+ ( event : DocActionEvent ) => {
122
+ if ( event . action === 'delete' ) {
123
+ goBack ( ) ;
124
+ }
125
+ } ,
126
+ [ goBack ]
127
+ ) ;
125
128
126
129
const publishDocModal = usePublishDocModal ( { docId : props . docId } ) ;
127
130
const localizationModal = useLocalizationModal ( {
@@ -147,7 +150,7 @@ export function DocEditor(props: DocEditorProps) {
147
150
>
148
151
< DOC_DATA_CONTEXT . Provider value = { data } >
149
152
< DEEPLINK_CONTEXT . Provider value = { deeplink } >
150
- < div className = "DocEditor" ref = { ref } >
153
+ < div className = "DocEditor" >
151
154
< LoadingOverlay
152
155
visible = { loading }
153
156
loaderProps = { { color : 'gray' , size : 'xl' } }
@@ -285,7 +288,7 @@ DocEditor.Field = (props: FieldProps) => {
285
288
}
286
289
) ;
287
290
return unsubscribe ;
288
- } , [ ] ) ;
291
+ } , [ props . draft , props . deepKey ] ) ;
289
292
290
293
useEffect ( ( ) => {
291
294
const translate = ( field as any ) . translate ;
@@ -821,7 +824,7 @@ DocEditor.ArrayField = (props: FieldProps) => {
821
824
}
822
825
) ;
823
826
return unsubscribe ;
824
- } , [ ] ) ;
827
+ } , [ props . draft , props . deepKey ] ) ;
825
828
826
829
// Focus the field that was just moved (for hotkey support).
827
830
useEffect ( ( ) => {
@@ -1159,7 +1162,7 @@ DocEditor.OneOfField = (props: FieldProps) => {
1159
1162
}
1160
1163
) ;
1161
1164
return unsubscribe ;
1162
- } , [ ] ) ;
1165
+ } , [ props . draft , props . deepKey ] ) ;
1163
1166
1164
1167
return (
1165
1168
< div className = "DocEditor__OneOfField" >
0 commit comments