Skip to content

Commit 9cc05f8

Browse files
committed
Tanstack queries will nou recalculate dependent tables when schema changes.
1 parent 55260d4 commit 9cc05f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/tanstack-react-query/src/hooks/useQuery.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,20 @@ function useQueryCore<
102102
};
103103

104104
React.useEffect(() => {
105-
if (!query) return;
105+
if (!query) return () => {};
106106

107107
(async () => {
108108
await fetchTables();
109109
})();
110+
111+
const l = powerSync.registerListener({
112+
schemaChanged: async () => {
113+
await fetchTables();
114+
queryClient.invalidateQueries({ queryKey: options.queryKey });
115+
}
116+
});
117+
118+
return () => l?.();
110119
}, [powerSync, sqlStatement, stringifiedParams]);
111120

112121
const queryFn = React.useCallback(async () => {

0 commit comments

Comments
 (0)