@korajs/react 0.0.0-canary-20261008174129

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dr. Obed Ehoneah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @korajs/react
2
+
3
+ React bindings for Kora.js: a provider, reactive queries, mutations, sync status, rich text and
4
+ presence. Hooks use `useSyncExternalStore`, so they are safe in concurrent rendering, StrictMode and
5
+ server rendering.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add korajs@beta @korajs/react@beta
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ <!-- docs-check-prelude
16
+ import { createApp, defineSchema, t } from 'korajs'
17
+ const schema = defineSchema({
18
+ version: 1,
19
+ collections: { todos: { fields: { title: t.string(), completed: t.boolean().default(false), createdAt: t.timestamp().auto() } } },
20
+ })
21
+ const app = createApp({ schema })
22
+ -->
23
+
24
+ ```tsx
25
+ import { createKoraHooks, KoraProvider } from '@korajs/react'
26
+
27
+ // Hooks typed by your schema
28
+ const { useCollection, useMutation, useQuery, useSyncStatus } = createKoraHooks<typeof app>()
29
+
30
+ export function Root() {
31
+ return (
32
+ <KoraProvider app={app} fallback={<p>Loading...</p>}>
33
+ <TodoList />
34
+ </KoraProvider>
35
+ )
36
+ }
37
+
38
+ function TodoList() {
39
+ const todos = useCollection('todos')
40
+ const open = useQuery(todos.where({ completed: false }).orderBy('createdAt'))
41
+ const addTodo = useMutation(todos.insert)
42
+ const status = useSyncStatus()
43
+
44
+ return (
45
+ <>
46
+ <button onClick={() => addTodo.mutate({ title: 'New todo' })}>Add</button>
47
+ {addTodo.error && <p role="alert">{addTodo.error.message}</p>}
48
+ <ul>
49
+ {open.map((todo) => (
50
+ <li key={todo.id}>{todo.title}</li>
51
+ ))}
52
+ </ul>
53
+ <small>
54
+ {status.status}, {status.pendingOperations} pending
55
+ </small>
56
+ </>
57
+ )
58
+ }
59
+ ```
60
+
61
+ - `KoraProvider` renders `fallback` until the local database is open.
62
+ - `useQuery` renders `[]` first and the rows right after mount, then re-renders only when the
63
+ result changes. `useQueryState` returns `{ data, error, ready }`.
64
+ - `useMutation` returns `{ mutate, mutateAsync, isLoading, error, reset }`; writes land locally at
65
+ once and upload in the background.
66
+ - `useSyncStatus()` returns the full status (`status`, `pendingOperations`, `lastSyncedAt`, ...)
67
+ and re-renders only when it changes.
68
+ - `useRichText`, `usePresence`, `useCollaborators` and `AuthBoundKoraProvider` cover collaborative
69
+ editing and per-user databases.
70
+
71
+ ## Documentation
72
+
73
+ [React Hooks guide](https://korajs.dev/guide/react-hooks) and the
74
+ [React API reference](https://korajs.dev/api/react).
75
+
76
+ ## License
77
+
78
+ MIT