@@ -3,7 +3,8 @@ import type { EditorChange, EditorConfiguration } from 'codemirror';
3
3
import type { SchemaReference } from 'codemirror-graphql/utils/SchemaReference' ;
4
4
import copyToClipboard from 'copy-to-clipboard' ;
5
5
import { parse , print } from 'graphql' ;
6
- import { useEffect , useRef , useState } from 'react' ;
6
+ // eslint-disable-next-line @typescript-eslint/no-restricted-imports -- TODO: check why query builder update only 1st field https://github.com/graphql/graphiql/issues/3836
7
+ import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
7
8
8
9
import { useExplorerContext } from '../explorer' ;
9
10
import { usePluginContext } from '../plugin' ;
@@ -344,9 +345,8 @@ export function useAutoCompleteLeafs({
344
345
345
346
// https://react.dev/learn/you-might-not-need-an-effect
346
347
347
- export const useEditorState = (
348
- editor : 'query' | 'variable' | 'header' ,
349
- ) : [ string , ( val : string ) => void ] => {
348
+ export const useEditorState = ( editor : 'query' | 'variable' | 'header' ) => {
349
+ 'use no memo' ; // eslint-disable-line react-compiler/react-compiler -- TODO: check why query builder update only 1st field https://github.com/graphql/graphiql/issues/3836
350
350
const context = useEditorContext ( {
351
351
nonNull : true ,
352
352
} ) ;
@@ -358,8 +358,14 @@ export const useEditorState = (
358
358
valueString = editorValue ;
359
359
}
360
360
361
- const handleEditorValue = ( value : string ) => editorInstance ?. setValue ( value ) ;
362
- return [ valueString , handleEditorValue ] ;
361
+ const handleEditorValue = useCallback (
362
+ ( value : string ) => editorInstance ?. setValue ( value ) ,
363
+ [ editorInstance ] ,
364
+ ) ;
365
+ return useMemo < [ string , ( val : string ) => void ] > (
366
+ ( ) => [ valueString , handleEditorValue ] ,
367
+ [ valueString , handleEditorValue ] ,
368
+ ) ;
363
369
} ;
364
370
365
371
/**
0 commit comments