localdb-ces6q 0.2.38 → 0.2.40
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/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +5 -3
- package/package.json +3 -3
package/dist/hooks.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { LocalDB } from './LocalDB.js';
|
2
2
|
import type { IDocument } from './types.js';
|
3
3
|
import type { KeyOf } from 'util-3gcvv/types/types.js';
|
4
|
-
export declare const useLocalDbDoc: <T extends Record<string, IDocument>, K extends KeyOf<T>>(db: LocalDB<T>, col: K, id: string, deps?: any[]) => T[K] | undefined;
|
4
|
+
export declare const useLocalDbDoc: <T extends Record<string, IDocument>, K extends KeyOf<T>>(db: LocalDB<T>, col: K, id: string | null | undefined, deps?: any[]) => T[K] | undefined;
|
5
5
|
export declare const useLocalDbDocs: <T extends Record<string, IDocument>, K extends KeyOf<T>>(db: LocalDB<T>, col: K, ids: string[] | null | undefined, deps?: any[]) => (T[K] | undefined)[];
|
package/dist/hooks.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
2
2
|
import { arraysEqual } from 'util-3gcvv/array.js';
|
3
3
|
export const useLocalDbDoc = (db, col, id, deps = [db, col, id]) => {
|
4
|
-
const [doc, setDoc] = useState(() => db.doc(col, id));
|
4
|
+
const [doc, setDoc] = useState(() => id == null ? undefined : db.doc(col, id));
|
5
5
|
useEffect(() => {
|
6
|
-
setDoc(db.doc(col, id));
|
7
|
-
|
6
|
+
setDoc(id == null ? undefined : db.doc(col, id));
|
7
|
+
if (id != null) {
|
8
|
+
return db.subToDoc(col, id, setDoc);
|
9
|
+
}
|
8
10
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
9
11
|
}, deps);
|
10
12
|
return doc;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "localdb-ces6q",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.40",
|
4
4
|
"description": "TypeScript ECMAScript Module Library Template",
|
5
5
|
"type": "module",
|
6
6
|
"module": "dist/index.js",
|
@@ -45,13 +45,13 @@
|
|
45
45
|
"@babel/preset-typescript": "^7.21.4",
|
46
46
|
"@jest/globals": "^29.5.0",
|
47
47
|
"@types/jest": "^29.5.0",
|
48
|
-
"@types/react": "^18.0.
|
48
|
+
"@types/react": "^18.0.33",
|
49
49
|
"jest-ts-webcompat-resolver": "^1.0.0",
|
50
50
|
"prettier": "^2.8.7",
|
51
51
|
"react": "^18.2.0",
|
52
52
|
"shelljs": "^0.8.5",
|
53
53
|
"shx": "^0.3.4",
|
54
|
-
"ts-jest": "^29.0
|
54
|
+
"ts-jest": "^29.1.0",
|
55
55
|
"typescript": "^5.0.3"
|
56
56
|
},
|
57
57
|
"publishConfig": {
|