Skip to content

Commit 8e67730

Browse files
committed
Use example
1 parent 1199074 commit 8e67730

File tree

2 files changed

+11
-6
lines changed
  • demos/react-supabase-todolist/src/app/views/todo-lists/edit
  • packages/react/src/hooks/watched

2 files changed

+11
-6
lines changed

demos/react-supabase-todolist/src/app/views/todo-lists/edit/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const TodoEditSection = () => {
4646
[listID]
4747
);
4848

49-
const { data: todos } = useQuery<TodoRecord>(
49+
const secondQuery = useQuery<TodoRecord>(
5050
/* sql */ `
5151
SELECT
5252
*
@@ -58,8 +58,12 @@ const TodoEditSection = () => {
5858
created_at DESC,
5959
id
6060
`,
61-
[listID]
61+
[listID],
62+
{
63+
streams: import.meta.env.VITE_USE_SYNC_STREAMS == 'true' ? [{ name: 'todos', parameters: { list: listID } }] : []
64+
}
6265
);
66+
const { data: todos } = secondQuery;
6367

6468
const [showPrompt, setShowPrompt] = React.useState(false);
6569
const nameInputRef = React.createRef<HTMLInputElement>();

packages/react/src/hooks/watched/useQuery.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ export function useQuery<RowType = any>(
6060
const powerSync = usePowerSync();
6161
if (!powerSync) {
6262
return {
63+
..._loadingState,
6364
isLoading: false,
64-
isFetching: false,
65-
data: [],
6665
error: new Error('PowerSync not configured.')
6766
};
6867
}
@@ -90,8 +89,10 @@ export function useQuery<RowType = any>(
9089
});
9190

9291
if (!streamsHaveSynced) {
93-
return { isLoading: true, isFetching: false, data: [], error: undefined };
92+
return { ..._loadingState };
9493
}
9594

96-
return runOnce ? single : watched;
95+
return (runOnce ? single : watched) ?? _loadingState;
9796
}
97+
98+
const _loadingState = { isLoading: true, isFetching: false, data: [], error: undefined };

0 commit comments

Comments
 (0)