@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.
Files changed (2) hide show
  1. package/README.md +56 -54
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,54 +1,56 @@
1
- # @loko/react
2
-
3
- React bindings for [`loko`](https://www.npmjs.com/package/loko) — offline storage + sync, with reactive hooks.
4
-
5
- ```bash
6
- npm install loko @loko/react
7
- ```
8
-
9
- ```tsx
10
- import { SyncProvider, useCollection, useSyncStatus } from "@loko/react";
11
- import { createSync, indexedDBStorage, restAdapter } from "loko";
12
-
13
- const sync = createSync({
14
- name: "myapp",
15
- storage: indexedDBStorage(),
16
- adapter: restAdapter({ url: "/api/sync" }),
17
- });
18
-
19
- function Todos() {
20
- const { items, put, remove, loading } = useCollection<Todo>("todos");
21
- const { status, sync: syncNow } = useSyncStatus();
22
- if (loading) return <p>Loading…</p>;
23
- return (
24
- <>
25
- <button onClick={() => syncNow()}>{status}</button>
26
- {items.map((t) => (
27
- <label key={t.id}>
28
- <input type="checkbox" checked={t.done} onChange={() => put({ ...t, done: !t.done })} />
29
- {t.text} <button onClick={() => remove(t.id)}>✕</button>
30
- </label>
31
- ))}
32
- </>
33
- );
34
- }
35
-
36
- export default function App() {
37
- return (
38
- <SyncProvider sync={sync}>
39
- <Todos />
40
- </SyncProvider>
41
- );
42
- }
43
- ```
44
-
45
- ## Hooks
46
-
47
- - `useCollection<T>(name)` → `{ items, loading, put, remove }`
48
- - `useDocument<T>(name, id)` → `{ item, loading, put, remove }`
49
- - `useSyncStatus()` → `{ status, sync }`
50
- - `useSync()` → the `Sync` instance from context
51
-
52
- All hooks are built on `useSyncExternalStore` for correct concurrent-mode behavior and re-render on local, sync, and cross-tab changes.
53
-
54
- Requires React 18+. License: MIT.
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
+ ![How loko works](https://raw.githubusercontent.com/MarkWasfy00/loko/main/public/diagram.png)
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.0",
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.0"
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.0"
52
+ "@markwasfy/loko": "0.1.1"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsup",