@@ -5,25 +5,18 @@ import { createContextQuery } from "./context";
55export function createUseContextQuery < TState extends TStateImpl > (
66 contexts : ReturnType < typeof createContextQuery < TState > >
77) {
8- const { StoreContext, ContextQuerySubscriptionContext } = contexts ;
8+ const { StoreContext } = contexts ;
99
1010 const useLocalContexts = ( ) => {
1111 const store = useContext ( StoreContext ) ;
12- const subscription = useContext ( ContextQuerySubscriptionContext ) ;
1312
1413 if ( ! store ) {
1514 throw new Error (
1615 "useContextQuery must be used within a ContextQueryProvider"
1716 ) ;
1817 }
1918
20- if ( ! subscription || ! subscription . subscribe ) {
21- throw new Error (
22- "ContextQuerySubscriptionContext not properly initialized"
23- ) ;
24- }
25-
26- return { store, subscription } ;
19+ return { store } ;
2720 } ;
2821
2922 const useContextBatchQuery = ( ) => {
@@ -49,7 +42,7 @@ export function createUseContextQuery<TState extends TStateImpl>(
4942 TState [ TKey ] ,
5043 ( value : TState [ TKey ] | ( ( prev : TState [ TKey ] ) => TState [ TKey ] ) ) => boolean ,
5144 ] => {
52- const { store, subscription } = useLocalContexts ( ) ;
45+ const { store } = useLocalContexts ( ) ;
5346 const [ state , setLocalState ] = useState < TState [ TKey ] > ( ( ) =>
5447 store . getStateByKey ( key )
5548 ) ;
@@ -59,14 +52,12 @@ export function createUseContextQuery<TState extends TStateImpl>(
5952 setLocalState ( newValue ) ;
6053 } ;
6154
62- if ( ! subscription . subscribe ) return ;
63-
64- const sub = subscription . subscribe ( key , handleChange ) ;
55+ const sub = store . subscribe ( key , handleChange ) ;
6556
6657 return ( ) => {
6758 sub . unsubscribe ( ) ;
6859 } ;
69- } , [ key , subscription . subscribe , store ] ) ;
60+ } , [ key , store ] ) ;
7061
7162 const setState = useCallback (
7263 ( value : TState [ TKey ] | ( ( prev : TState [ TKey ] ) => TState [ TKey ] ) ) => {
0 commit comments