Skip to content

Commit a65cd8c

Browse files
chore: added isLoading to docs (#283)
1 parent 81f0f53 commit a65cd8c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

.changeset/green-dogs-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/react': patch
3+
---
4+
5+
chore: Added `isLoading` example to README

packages/react/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,38 @@ export const TodoListDisplay = () => {
8181
</View>
8282
}
8383
```
84+
85+
#### Query Loading
86+
87+
The response from `useQuery` includes the `isLoading` and `isFetching` properties, which indicate the current state of data retrieval. This can be used to show loading spinners or conditional widgets.
88+
89+
```JSX
90+
// TodoListDisplay.jsx
91+
import { useQuery } from "@powersync/react";
92+
93+
export const TodoListsDisplayDemo = () => {
94+
const { data: todoLists, isLoading, isFetching } = useQuery('SELECT * FROM lists');
95+
return (
96+
<div>
97+
<h1>Todo Lists {isFetching ? '' : ''}</h1>
98+
<div
99+
style={{
100+
opacity: isLoading ? 1 : 0,
101+
transition: 'opacity 0.5s ease-in-out'
102+
}}>
103+
Loading todo lists...
104+
</div>
105+
<ul
106+
style={{
107+
opacity: isLoading ? 0 : 1,
108+
transition: 'opacity 1s ease-in-out'
109+
}}>
110+
{todoLists.map(() => (
111+
<li key={l.id}>{JSON.stringify(l)}</li>
112+
))}
113+
</ul>
114+
</div>
115+
);
116+
};
117+
118+
```

0 commit comments

Comments
 (0)