@triplit/react 0.0.28 → 0.0.29
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/use-query.d.ts +6 -0
- package/dist/use-query.js +25 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './use-query';
|
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './use-query';
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { QueryResults, TriplitClient, ClientQuery, toBuilder } from '@triplit/client';
|
2
|
+
export declare function useQuery<CQ extends ClientQuery<any>>(client: TriplitClient<any>, query: toBuilder<CQ>): {
|
3
|
+
fetchingLocal: boolean;
|
4
|
+
results: QueryResults<CQ> | undefined;
|
5
|
+
error: null;
|
6
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { useEffect, useState } from 'react';
|
2
|
+
export function useQuery(client, query) {
|
3
|
+
const [results, setResults] = useState(undefined);
|
4
|
+
const [fetchingLocal, setFetchingLocal] = useState(false);
|
5
|
+
// const [fetchingRemote, setFetchingRemote] = useState(false);
|
6
|
+
const builtQuery = query.build();
|
7
|
+
const stringifiedQuery = JSON.stringify(builtQuery);
|
8
|
+
useEffect(() => {
|
9
|
+
setResults(undefined);
|
10
|
+
setFetchingLocal(true);
|
11
|
+
const unsubscribe = client.subscribe(builtQuery, (localResults) => {
|
12
|
+
setFetchingLocal(false);
|
13
|
+
setResults(localResults);
|
14
|
+
});
|
15
|
+
return () => {
|
16
|
+
unsubscribe();
|
17
|
+
};
|
18
|
+
}, [stringifiedQuery, client]);
|
19
|
+
return {
|
20
|
+
fetchingLocal,
|
21
|
+
// fetchingRemote,
|
22
|
+
results,
|
23
|
+
error: null,
|
24
|
+
};
|
25
|
+
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@triplit/react",
|
3
3
|
"packageManager": "yarn@3.4.1",
|
4
|
-
"version": "0.0.
|
4
|
+
"version": "0.0.29",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"typings": "dist/index.d.ts",
|
7
7
|
"type": "module",
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"/dist"
|
15
15
|
],
|
16
16
|
"dependencies": {
|
17
|
-
"@triplit/client": "^0.0.
|
17
|
+
"@triplit/client": "^0.0.29"
|
18
18
|
},
|
19
19
|
"devDependencies": {
|
20
20
|
"@types/react": "^18.2.0",
|