@@ -80,6 +80,8 @@ let JsonEditorTmpComp = (function () {
80
80
81
81
const wrapperRef = useRef < HTMLDivElement > ( null ) ;
82
82
const view = useRef < EditorViewType | null > ( null ) ;
83
+ const initialized = useRef ( false ) ;
84
+ const state = useRef < EditorState | null > ( null ) ;
83
85
const editContent = useRef < string > ( ) ;
84
86
const { extensions } = useExtensions ( {
85
87
codeType : "PureJSON" ,
@@ -102,21 +104,20 @@ let JsonEditorTmpComp = (function () {
102
104
} ) ;
103
105
104
106
useEffect ( ( ) => {
105
- if ( wrapperRef . current && ! view . current ) {
106
- const state = EditorState . create ( {
107
+ if ( ! initialized . current && wrapperRef . current ) {
108
+ state . current = EditorState . create ( {
107
109
doc : JSON . stringify ( props . value . value , null , 2 ) ,
108
110
extensions,
109
111
} ) ;
110
- view . current = new EditorView ( { state, parent : wrapperRef . current } ) ;
111
- }
112
- if ( wrapperRef . current && ( props . showVerticalScrollbar || ! props . showVerticalScrollbar ) ) {
113
- const state = EditorState . create ( {
114
- doc : JSON . stringify ( props . value . value , null , 2 ) ,
115
- extensions,
116
- } ) ;
117
- view . current = new EditorView ( { state, parent : wrapperRef . current } ) ;
118
112
}
119
113
} , [ wrapperRef . current , props . showVerticalScrollbar ] ) ;
114
+
115
+ useEffect ( ( ) => {
116
+ if ( state . current && wrapperRef . current ) {
117
+ view . current = new EditorView ( { state : state . current , parent : wrapperRef . current } ) ;
118
+ initialized . current = true ;
119
+ }
120
+ } , [ props . showVerticalScrollbar ] )
120
121
121
122
if ( wrapperRef . current && view . current && ! editContent . current ) {
122
123
const state = EditorState . create ( {
0 commit comments