@poolse/react 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@poolse/react` are documented here. Format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
5
+ [semver](https://semver.org).
6
+
7
+ ## [0.1.0] — 2026-06-01
8
+
9
+ First publishable release.
10
+
11
+ ### Added
12
+
13
+ - `<PoolseProvider>` — mount-once SDK instance with ref-stable callbacks
14
+ (safe to pass `config={{getToken: () => ...}}` inline on every render).
15
+ - `usePoolse()` — raw `Poolse` instance escape hatch.
16
+ - Realtime hooks: `useMe`, `useConversations`, `useConversation`,
17
+ `useMembers`, `useMessages`, `useThread`, `useReactions`, `useTyping`,
18
+ `usePresence`, `useRealtimeStatus`.
19
+ - Attachments: `useAttachmentUpload`, `useAttachmentUrl`.
20
+ - Real-time conversation list — `useConversations` subscribes to the
21
+ user's `user:<id>` channel and prepends on `conversation:created`
22
+ push (no manual refetch needed).
23
+ - Optimistic message send with id-based dedup: `useMessages.send()`
24
+ inserts under the same id the server will assign, so realtime echo
25
+ upserts in place.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Poolse
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,82 @@
1
+ # `@poolse/react`
2
+
3
+ Headless React hooks for **[poolse](https://poolse.dev)** — realtime chat infrastructure.
4
+
5
+ Provider + hooks for `useMe`, `useConversations`, `useMessages`, `useTyping`, `usePresence`, `useReactions`, `useThread`, `useAttachmentUpload`, and more. No UI — bring your own, or use the prebuilt components in **[`@poolse/react-ui`](https://www.npmjs.com/package/@poolse/react-ui)**.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @poolse/react @poolse/sdk
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```tsx
16
+ import { PoolseProvider, useMessages } from '@poolse/react';
17
+
18
+ function App() {
19
+ return (
20
+ <PoolseProvider
21
+ config={{
22
+ apiUrl: 'https://chat.example.com',
23
+ getToken: async () => {
24
+ const res = await fetch('/api/chat-token', { method: 'POST' });
25
+ const { token } = await res.json();
26
+ return token;
27
+ },
28
+ }}
29
+ >
30
+ <Chat conversationId="<conversation-id>" />
31
+ </PoolseProvider>
32
+ );
33
+ }
34
+
35
+ function Chat({ conversationId }: { conversationId: string }) {
36
+ const { messages, send, loading } = useMessages(conversationId);
37
+
38
+ if (loading) return <div>Loading…</div>;
39
+ return (
40
+ <ul>
41
+ {messages.map((m) => (
42
+ <li key={m.id}>{m.body}</li>
43
+ ))}
44
+ <button onClick={() => send({ body: 'Hi!' })}>Send hi</button>
45
+ </ul>
46
+ );
47
+ }
48
+ ```
49
+
50
+ ## Hooks at a glance
51
+
52
+ | Hook | Returns |
53
+ | ------------------------------- | ----------------------------------------------------------------- |
54
+ | `useMe()` | The signed-in End User |
55
+ | `useConversations()` | List + `create` + realtime new-conversation push |
56
+ | `useConversation(id)` | Single conversation read + refetch |
57
+ | `useMembers(convId)` | Membership list + add/remove helpers |
58
+ | `useMessages(convId)` | Live messages + `send` + pagination + optimistic dedup |
59
+ | `useThread(convId, rootId)` | Replies + `sendReply` + pagination |
60
+ | `useTyping(convId)` | Live `typing` set + `signalTyping` (debounced) |
61
+ | `usePresence(convId)` | Live `online` set |
62
+ | `useReactions(messageId, opts)` | Live reaction map + add/remove |
63
+ | `useAttachmentUpload()` | Stateful `upload(file)` with `uploading` + `error` |
64
+ | `useAttachmentUrl(id)` | Presigned download URL |
65
+ | `useRealtimeStatus()` | Socket lifecycle (connecting / connected / reconnecting / closed) |
66
+ | `usePoolse()` | Raw `Poolse` instance (escape hatch) |
67
+
68
+ ## What the provider gives you
69
+
70
+ - **One `Poolse` instance per mount.** Stable WebSocket and channel subscriptions for the life of the provider. Pass a fresh inline `config={{ getToken: … }}` on every render — `getToken` is read from a ref each call, so the SDK doesn't tear down.
71
+ - **Auto-rejoin** when the socket drops + reconnects.
72
+ - **Optimistic message dedup** by client-generated id — `useMessages.send()` adds the row under the same id the server will assign, so the realtime echo upserts in place rather than appending a duplicate.
73
+
74
+ ## Documentation
75
+
76
+ - Full hook reference + recipes — <https://poolse.dev/docs/react>
77
+ - Source — <https://github.com/poolse-hq/js-sdk>
78
+ - Issues — <https://github.com/poolse-hq/js-sdk/issues>
79
+
80
+ ## License
81
+
82
+ MIT