@powersync/react 0.0.0-dev-20250728130541 → 0.0.0-dev-20250730072702
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -391,3 +391,28 @@ function MyWidget() {
|
|
|
391
391
|
)
|
|
392
392
|
}
|
|
393
393
|
```
|
|
394
|
+
|
|
395
|
+
## Query Subscriptions
|
|
396
|
+
|
|
397
|
+
The `useWatchedQuerySubscription` hook lets you access the state of an externally managed `WatchedQuery` instance. Managing a query outside of a component enables in-memory caching and sharing of results between multiple subscribers. This reduces async loading time during component mount (thanks to in-memory caching) and minimizes the number of SQLite queries (by sharing results between multiple components).
|
|
398
|
+
|
|
399
|
+
```jsx
|
|
400
|
+
// The lifecycle of this query is managed outside of any individual React component.
|
|
401
|
+
// The data is kept up-to-date in the background and can be shared by multiple subscribers.
|
|
402
|
+
const listsQuery = powerSync.query({ sql: 'SELECT * FROM lists' }).differentialWatch();
|
|
403
|
+
|
|
404
|
+
export const ContentComponent = () => {
|
|
405
|
+
// Subscribes to the `listsQuery` instance. The subscription is automatically
|
|
406
|
+
// cleaned up when the component unmounts. The `data` value always reflects
|
|
407
|
+
// the latest state of the query.
|
|
408
|
+
const { data: lists } = useWatchedQuerySubscription(listsQuery);
|
|
409
|
+
|
|
410
|
+
return (
|
|
411
|
+
<View>
|
|
412
|
+
{lists.map((l) => (
|
|
413
|
+
<Text key={l.id}>{JSON.stringify(l)}</Text>
|
|
414
|
+
))}
|
|
415
|
+
</View>
|
|
416
|
+
);
|
|
417
|
+
};
|
|
418
|
+
```
|
|
@@ -17,9 +17,10 @@ import { AdditionalOptions, DifferentialHookOptions, QueryResult, ReadonlyQueryR
|
|
|
17
17
|
* }
|
|
18
18
|
*
|
|
19
19
|
* export const DiffComponent = () => {
|
|
20
|
-
* //
|
|
20
|
+
* // Providing a `rowComparator` results in the hook using an incremental query under the hood.
|
|
21
|
+
* // An incremental query will only emit results when a change to the result set occurs.
|
|
21
22
|
* // The internal array object references are maintained for unchanged rows.
|
|
22
|
-
* // The returned lists array is read only when a `
|
|
23
|
+
* // The returned lists array is read only when a `rowComparator` is provided.
|
|
23
24
|
* const { data: lists } = useQuery('SELECT * from lists', [], {
|
|
24
25
|
* rowComparator: {
|
|
25
26
|
* keyBy: (item) => item.id,
|
|
@@ -3,7 +3,7 @@ import { InternalHookOptions } from './watch-utils';
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal This is not exported from the index.ts
|
|
5
5
|
*
|
|
6
|
-
* When
|
|
6
|
+
* When an incremental query is used the return type is readonly. This is required
|
|
7
7
|
* since the implementation requires a stable ref.
|
|
8
8
|
* For legacy compatibility we allow mutating when a standard query is used. Mutations should
|
|
9
9
|
* not affect the internal implementation in this case.
|
|
@@ -3,7 +3,7 @@ import { useWatchedQuerySubscription } from './useWatchedQuerySubscription';
|
|
|
3
3
|
/**
|
|
4
4
|
* @internal This is not exported from the index.ts
|
|
5
5
|
*
|
|
6
|
-
* When
|
|
6
|
+
* When an incremental query is used the return type is readonly. This is required
|
|
7
7
|
* since the implementation requires a stable ref.
|
|
8
8
|
* For legacy compatibility we allow mutating when a standard query is used. Mutations should
|
|
9
9
|
* not affect the internal implementation in this case.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/react",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20250730072702",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://docs.powersync.com",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@powersync/common": "0.0.0-dev-
|
|
25
|
+
"@powersync/common": "0.0.0-dev-20250730072702",
|
|
26
26
|
"react": "*"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"react": "18.3.1",
|
|
34
34
|
"react-dom": "18.3.1",
|
|
35
35
|
"react-error-boundary": "^4.1.0",
|
|
36
|
-
"@powersync/common": "0.0.0-dev-
|
|
37
|
-
"@powersync/web": "0.0.0-dev-
|
|
36
|
+
"@powersync/common": "0.0.0-dev-20250730072702",
|
|
37
|
+
"@powersync/web": "0.0.0-dev-20250730072702"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc -b",
|