@@ -15,8 +15,12 @@ import {
1515 isUnionType ,
1616} from 'graphql' ;
1717import { FC , ReactElement , ReactNode , useEffect } from 'react' ;
18- import { SchemaContextType , useSchemaStore } from '@graphiql/react' ;
19- import { createStore , useStore } from 'zustand' ;
18+ import {
19+ createBoundedUseStore ,
20+ SchemaContextType ,
21+ useSchemaStore ,
22+ } from '@graphiql/react' ;
23+ import { createStore } from 'zustand' ;
2024
2125export type DocExplorerFieldDef =
2226 | GraphQLField < unknown , unknown >
@@ -150,7 +154,7 @@ export const docExplorerStore = createStore<DocExplorerContextType>(
150154 set ( state => {
151155 const oldNavStack = state . explorerNavStack ;
152156 if ( oldNavStack . length === 1 ) {
153- return oldNavStack ;
157+ return state ;
154158 }
155159 // Spread is needed
156160 const newNavStack : DocExplorerNavStack = [ ...INITIAL_NAV_STACK ] ;
@@ -257,11 +261,7 @@ export const DocExplorerContextProvider: FC<{
257261 return children as ReactElement ;
258262} ;
259263
260- function useDocExplorerStore < T > (
261- selector : ( state : DocExplorerContextType ) => T ,
262- ) : T {
263- return useStore ( docExplorerStore , selector ) ;
264- }
264+ const useDocExplorerStore = createBoundedUseStore ( docExplorerStore ) ;
265265
266266export const useDocExplorer = ( ) =>
267267 useDocExplorerStore ( state => state . explorerNavStack ) ;
0 commit comments