Skip to content

Commit

Permalink
move updateQueryStringURL to reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithpabbati committed Jun 20, 2020
1 parent 83cb9d8 commit c40b524
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const initialBrowserState: BrowserState = {
variables: parseQueryStringURL(window.location.search).variables,
operationName: parseQueryStringURL(window.location.search).operationName,
},
queryStringParamsURL: '',
};

export const initialBrowserContextState: BrowserState & BrowserHandlers = {
Expand All @@ -47,6 +48,7 @@ const browserReducer: BrowserReducer = (state, action) => {
...state.queryStringParams,
[parameter]: value,
},
queryStringParamsURL: updateQueryStringURL(state.queryStringParams),
};
}
default: {
Expand All @@ -72,8 +74,8 @@ export function BrowserProvider({ children }: BrowserProviderProps) {
);

React.useEffect(() => {
updateQueryStringURL(state.queryStringParams);
}, [state.queryStringParams]);
history.replaceState(null, document.title, state.queryStringParamsURL);
}, [state.queryStringParamsURL]);

return (
<BrowserContext.Provider
Expand Down
1 change: 1 addition & 0 deletions packages/graphiql/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export type SessionState = {

export type BrowserState = {
queryStringParams: any;
queryStringParamsURL: string;
};
2 changes: 1 addition & 1 deletion packages/graphiql/src/utility/updateQueryStringURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export function updateQueryStringURL(parameters: any) {
);
})
.join('&');
history.replaceState(null, document.title, newSearch);
return newSearch;
}
}

0 comments on commit c40b524

Please sign in to comment.