Skip to content

Commit 44b18e4

Browse files
authored
fix useOperationsEditorState wasn't returned updated return value (#4063)
* add `graphiql.css`, CSS file without CSS without importing fonts and monaco-editor styles * add `graphiql.css`, CSS file without CSS without importing fonts and monaco-editor styles * fix: `useOperationsEditorState` wasn’t returning the updated editor value * Update packages/graphiql-react/src/utility/hooks.ts
1 parent 8f14fff commit 44b18e4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

.changeset/yellow-coins-act.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphiql/react': patch
3+
'graphiql': patch
4+
---
5+
6+
fix `useOperationsEditorState` wasn't returned updated return value

packages/graphiql-react/src/utility/hooks.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ export const useEditorState = (
5151
// eslint-disable-next-line react-hooks/react-compiler -- TODO: check why query builder update only 1st field https://github.com/graphql/graphiql/issues/3836
5252
'use no memo';
5353
const editorInstance = useGraphiQL(state => state[`${editor}Editor`]);
54-
const editorValue = editorInstance?.getValue() ?? '';
55-
54+
const [editorValue, setEditorValue] = useState(
55+
() => editorInstance?.getValue() ?? '',
56+
);
5657
const handleChange = useCallback(
57-
(value: string) => editorInstance?.setValue(value),
58+
(value: string) => {
59+
editorInstance?.setValue(value);
60+
setEditorValue(value);
61+
},
5862
[editorInstance],
5963
);
6064
return useMemo(

0 commit comments

Comments
 (0)