@instantdb/react-common 0.22.131 → 0.22.132

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/react-common",
3
- "version": "0.22.131",
3
+ "version": "0.22.132",
4
4
  "description": "Instant DB shared components for React and React Native",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/react-common",
6
6
  "repository": {
@@ -53,8 +53,8 @@
53
53
  "react": ">=16"
54
54
  },
55
55
  "dependencies": {
56
- "@instantdb/core": "0.22.131",
57
- "@instantdb/version": "0.22.131"
56
+ "@instantdb/core": "0.22.132",
57
+ "@instantdb/version": "0.22.132"
58
58
  },
59
59
  "scripts": {
60
60
  "test": "vitest",
@@ -137,7 +137,7 @@ export default abstract class InstantReactAbstractDatabase<
137
137
  * const room = db.room('chat', roomId);
138
138
  * const { peers } = db.rooms.usePresence(room);
139
139
  */
140
- room<RoomType extends keyof Rooms>(
140
+ room<RoomType extends string & keyof Rooms>(
141
141
  type: RoomType = '_defaultRoomType' as RoomType,
142
142
  id: string = '_defaultRoomId',
143
143
  ) {
@@ -61,7 +61,7 @@ export const defaultActivityStopTimeout = 1_000;
61
61
  */
62
62
  export function useTopicEffect<
63
63
  RoomSchema extends RoomSchemaShape,
64
- RoomType extends keyof RoomSchema,
64
+ RoomType extends string & keyof RoomSchema,
65
65
  TopicType extends keyof RoomSchema[RoomType]['topics'],
66
66
  >(
67
67
  room: InstantReactRoom<any, RoomSchema, RoomType>,
@@ -76,6 +76,7 @@ export function useTopicEffect<
76
76
 
77
77
  useEffect(() => {
78
78
  const unsub = room.core._reactor.subscribeTopic(
79
+ room.type,
79
80
  room.id,
80
81
  topic,
81
82
  (event, peer) => {
@@ -104,13 +105,13 @@ export function useTopicEffect<
104
105
  */
105
106
  export function usePublishTopic<
106
107
  RoomSchema extends RoomSchemaShape,
107
- RoomType extends keyof RoomSchema,
108
+ RoomType extends string & keyof RoomSchema,
108
109
  TopicType extends keyof RoomSchema[RoomType]['topics'],
109
110
  >(
110
111
  room: InstantReactRoom<any, RoomSchema, RoomType>,
111
112
  topic: TopicType,
112
113
  ): (data: RoomSchema[RoomType]['topics'][TopicType]) => void {
113
- useEffect(() => room.core._reactor.joinRoom(room.id), [room.id]);
114
+ useEffect(() => room.core._reactor.joinRoom(room.type, room.id), [room.id]);
114
115
 
115
116
  const publishTopic = useCallback(
116
117
  (data) => {
@@ -146,7 +147,7 @@ export function usePublishTopic<
146
147
  */
147
148
  export function usePresence<
148
149
  RoomSchema extends RoomSchemaShape,
149
- RoomType extends keyof RoomSchema,
150
+ RoomType extends string & keyof RoomSchema,
150
151
  Keys extends keyof RoomSchema[RoomType]['presence'],
151
152
  >(
152
153
  room: InstantReactRoom<any, RoomSchema, RoomType>,
@@ -203,13 +204,16 @@ export function usePresence<
203
204
  */
204
205
  export function useSyncPresence<
205
206
  RoomSchema extends RoomSchemaShape,
206
- RoomType extends keyof RoomSchema,
207
+ RoomType extends string & keyof RoomSchema,
207
208
  >(
208
209
  room: InstantReactRoom<any, RoomSchema, RoomType>,
209
210
  data: Partial<RoomSchema[RoomType]['presence']>,
210
211
  deps?: any[],
211
212
  ): void {
212
- useEffect(() => room.core._reactor.joinRoom(room.id, data), [room.id]);
213
+ useEffect(
214
+ () => room.core._reactor.joinRoom(room.type, room.id, data),
215
+ [room.id],
216
+ );
213
217
  useEffect(() => {
214
218
  return room.core._reactor.publishPresence(room.type, room.id, data);
215
219
  }, [room.type, room.id, deps ?? JSON.stringify(data)]);
@@ -236,7 +240,7 @@ export function useSyncPresence<
236
240
  */
237
241
  export function useTypingIndicator<
238
242
  RoomSchema extends RoomSchemaShape,
239
- RoomType extends keyof RoomSchema,
243
+ RoomType extends string & keyof RoomSchema,
240
244
  >(
241
245
  room: InstantReactRoom<any, RoomSchema, RoomType>,
242
246
  inputName: string,
@@ -320,7 +324,7 @@ export const rooms = {
320
324
  export class InstantReactRoom<
321
325
  Schema extends InstantSchemaDef<any, any, any>,
322
326
  RoomSchema extends RoomSchemaShape,
323
- RoomType extends keyof RoomSchema,
327
+ RoomType extends string & keyof RoomSchema,
324
328
  > {
325
329
  core: InstantCoreDatabase<Schema, boolean>;
326
330
  /** @deprecated use `core` instead */