Skip to content

Commit

Permalink
sync persist header prop if it changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMightyPenguin committed Nov 29, 2022
1 parent fe0fa20 commit 30984df
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/graphiql-react/src/editor/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {
visit,
} from 'graphql';
import { VariableToType } from 'graphql-language-service';
import { ReactNode, useCallback, useMemo, useState } from 'react';
import {
ReactNode,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';

import { useStorageContext } from '../storage';
import { createContextHook, createNullableContext } from '../utility/context';
Expand Down Expand Up @@ -336,6 +343,14 @@ export function EditorContextProvider(props: EditorContextProviderProps) {
[storage, tabState, headerEditor],
);

const lastShouldPersistHeadersProp = useRef<boolean | undefined>(undefined);
useEffect(() => {
const propValue = Boolean(props.shouldPersistHeaders);
if (lastShouldPersistHeadersProp.current !== propValue) {
setShouldPersistHeaders(propValue);
}
}, [props.shouldPersistHeaders, setShouldPersistHeaders]);

const synchronizeActiveTabValues = useSynchronizeActiveTabValues({
queryEditor,
variableEditor,
Expand Down

0 comments on commit 30984df

Please sign in to comment.