@markwasfy/loko-react 0.1.0 → 0.1.1
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 +56 -54
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
# @loko
|
|
2
|
-
|
|
3
|
-
React bindings for [
|
|
4
|
-
|
|
5
|
-
```bash
|
|
6
|
-
npm install loko @loko
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- `
|
|
50
|
-
- `
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
# @markwasfy/loko-react
|
|
2
|
+
|
|
3
|
+
React bindings for [`@markwasfy/loko`](https://www.npmjs.com/package/@markwasfy/loko) — offline storage + sync, with reactive hooks.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @markwasfy/loko @markwasfy/loko-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { SyncProvider, useCollection, useSyncStatus } from "@markwasfy/loko-react";
|
|
13
|
+
import { createSync, indexedDBStorage, restAdapter } from "@markwasfy/loko";
|
|
14
|
+
|
|
15
|
+
const sync = createSync({
|
|
16
|
+
name: "myapp",
|
|
17
|
+
storage: indexedDBStorage(),
|
|
18
|
+
adapter: restAdapter({ url: "/api/sync" }),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function Todos() {
|
|
22
|
+
const { items, put, remove, loading } = useCollection<Todo>("todos");
|
|
23
|
+
const { status, sync: syncNow } = useSyncStatus();
|
|
24
|
+
if (loading) return <p>Loading…</p>;
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
<button onClick={() => syncNow()}>{status}</button>
|
|
28
|
+
{items.map((t) => (
|
|
29
|
+
<label key={t.id}>
|
|
30
|
+
<input type="checkbox" checked={t.done} onChange={() => put({ ...t, done: !t.done })} />
|
|
31
|
+
{t.text} <button onClick={() => remove(t.id)}>✕</button>
|
|
32
|
+
</label>
|
|
33
|
+
))}
|
|
34
|
+
</>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default function App() {
|
|
39
|
+
return (
|
|
40
|
+
<SyncProvider sync={sync}>
|
|
41
|
+
<Todos />
|
|
42
|
+
</SyncProvider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Hooks
|
|
48
|
+
|
|
49
|
+
- `useCollection<T>(name)` → `{ items, loading, put, remove }`
|
|
50
|
+
- `useDocument<T>(name, id)` → `{ item, loading, put, remove }`
|
|
51
|
+
- `useSyncStatus()` → `{ status, sync }`
|
|
52
|
+
- `useSync()` → the `Sync` instance from context
|
|
53
|
+
|
|
54
|
+
All hooks are built on `useSyncExternalStore` for correct concurrent-mode behavior and re-render on local, sync, and cross-tab changes.
|
|
55
|
+
|
|
56
|
+
Requires React 18+. License: MIT.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markwasfy/loko-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React bindings for loko — offline storage + sync hooks (useCollection, useDocument, useSyncStatus).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
],
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=18",
|
|
42
|
-
"@markwasfy/loko": "^0.1.
|
|
42
|
+
"@markwasfy/loko": "^0.1.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@testing-library/react": "^16.1.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"react-dom": "^18.3.1",
|
|
50
50
|
"tsup": "^8.3.5",
|
|
51
51
|
"typescript": "^5.7.2",
|
|
52
|
-
"@markwasfy/loko": "0.1.
|
|
52
|
+
"@markwasfy/loko": "0.1.1"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsup",
|