File size: 567 Bytes
6a839c1
423b87b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// @ts-nocheck
import { getContext } from "svelte";
import type { Room } from "@liveblocks/client";
import { roomSymbol } from "./symbols";

/**
 * Works similarly to `liveblocks-react` useRoom
 * https://liveblocks.io/docs/api-reference/liveblocks-react#useRoom
 *
 * This does NOT return a Svelte store, just the plain room object
 * const room = useRoom()
 * room.history.undo()
 */
export function useRoom(): Room {
  const room = getContext<Room>(roomSymbol);

  if (!room) {
    throw new Error("Use RoomProvider as parent with id prop");
  }

  return room;
}