@@ -38,6 +38,7 @@ export {
38
38
SchemaContext ,
39
39
SchemaContextProvider ,
40
40
SettingsIcon ,
41
+ Spinner ,
41
42
StopIcon ,
42
43
StorageContext ,
43
44
StorageContextProvider ,
@@ -53,7 +54,6 @@ export {
53
54
useMergeQuery ,
54
55
usePrettifyEditors ,
55
56
useSchemaContext ,
56
- useSelectHistoryItem ,
57
57
useStorageContext ,
58
58
} from '@graphiql/react' ;
59
59
@@ -93,15 +93,20 @@ function useMockedEditor(
93
93
onEdit ?: ( newValue : string ) => void ,
94
94
) {
95
95
const editorContext = useEditorContext ( { nonNull : true } ) ;
96
- const [ code , setCode ] = useState (
97
- value ?? editorContext [ NAME_TO_INITIAL_VALUE [ name ] ] ,
98
- ) ;
96
+ const [ code , setCode ] = useState ( ( ) => {
97
+ const initialValueProp = NAME_TO_INITIAL_VALUE [ name ] ;
98
+ return (
99
+ value ??
100
+ ( initialValueProp ? editorContext [ initialValueProp ] : undefined ) ??
101
+ ''
102
+ ) ;
103
+ } ) ;
99
104
const ref = useRef < HTMLDivElement > ( null ) ;
100
105
101
106
const setEditor =
102
107
editorContext [ `set${ name . slice ( 0 , 1 ) . toUpperCase ( ) } ${ name . slice ( 1 ) } Editor` ] ;
103
108
104
- const getValueRef = useRef < ( ) => string > ( ) ;
109
+ const getValueRef = useRef < ( ) => string > ( ( ) => code ) ;
105
110
useEffect ( ( ) => {
106
111
getValueRef . current = ( ) => code ;
107
112
} , [ code ] ) ;
@@ -180,28 +185,28 @@ function useMockedEditor(
180
185
return ref ;
181
186
}
182
187
183
- export const useHeaderEditor : typeof _useHeaderEditor = function useHeaderEditor ( {
184
- onEdit ,
185
- } ) {
186
- return useMockedEditor ( 'header' , undefined , onEdit ) ;
188
+ export const useHeaderEditor : typeof _useHeaderEditor = function useHeaderEditor (
189
+ props ,
190
+ ) {
191
+ return useMockedEditor ( 'header' , undefined , props ?. onEdit ) ;
187
192
} ;
188
193
189
- export const useQueryEditor : typeof _useQueryEditor = function useQueryEditor ( {
190
- onEdit ,
191
- } ) {
192
- return useMockedEditor ( 'query' , undefined , onEdit ) ;
194
+ export const useQueryEditor : typeof _useQueryEditor = function useQueryEditor (
195
+ props ,
196
+ ) {
197
+ return useMockedEditor ( 'query' , undefined , props ?. onEdit ) ;
193
198
} ;
194
199
195
- export const useResponseEditor : typeof _useResponseEditor = function useResponseEditor ( {
196
- value ,
197
- } ) {
198
- return useMockedEditor ( 'response' , value ) ;
200
+ export const useResponseEditor : typeof _useResponseEditor = function useResponseEditor (
201
+ props ,
202
+ ) {
203
+ return useMockedEditor ( 'response' , props ?. value ) ;
199
204
} ;
200
205
201
- export const useVariableEditor : typeof _useVariableEditor = function useVariableEditor ( {
202
- onEdit ,
203
- } ) {
204
- return useMockedEditor ( 'variable' , undefined , onEdit ) ;
206
+ export const useVariableEditor : typeof _useVariableEditor = function useVariableEditor (
207
+ props ,
208
+ ) {
209
+ return useMockedEditor ( 'variable' , undefined , props ?. onEdit ) ;
205
210
} ;
206
211
207
212
export const HeaderEditor : typeof _HeaderEditor = function HeaderEditor ( props ) {
0 commit comments