File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export type QueryResult<T> = {
2020 /**
2121 * Function used to run the query again.
2222 */
23- refresh ?: ( ) => Promise < void > ;
23+ refresh ?: ( signal ?: AbortSignal ) => Promise < void > ;
2424} ;
2525
2626/**
@@ -112,9 +112,14 @@ export const useQuery = <T = any>(
112112 }
113113 } ;
114114
115- const fetchTables = async ( ) => {
115+ const fetchTables = async ( signal ?: AbortSignal ) => {
116116 try {
117117 const tables = await powerSync . resolveTables ( sqlStatement , memoizedParams , memoizedOptions ) ;
118+
119+ if ( signal ?. aborted ) {
120+ return ;
121+ }
122+
118123 setTables ( tables ) ;
119124 } catch ( e ) {
120125 console . error ( 'Failed to fetch tables:' , e ) ;
@@ -125,7 +130,7 @@ export const useQuery = <T = any>(
125130 React . useEffect ( ( ) => {
126131 const abortController = new AbortController ( ) ;
127132 const updateData = async ( ) => {
128- await fetchTables ( ) ;
133+ await fetchTables ( abortController . signal ) ;
129134 await fetchData ( abortController . signal ) ;
130135 } ;
131136
@@ -150,7 +155,7 @@ export const useQuery = <T = any>(
150155 powerSync . onChangeWithCallback (
151156 {
152157 onChange : async ( ) => {
153- await fetchData ( ) ;
158+ await fetchData ( abortController . current . signal ) ;
154159 } ,
155160 onError ( e ) {
156161 handleError ( e ) ;
You can’t perform that action at this time.
0 commit comments