React Api Reference
    Preparing search index...

    Class useRealtimeStore

    useRealtimeStore provides reactive APIs to store, retrieve, and listen to shared key-value data in real time across all meeting participants.

    Index

    Constructors

    Properties

    Methods

    Events

    Constructors

    Properties

    key: string
    • This represents the unique identifier for a value stored in the Realtime Store.
    • Each key is shared across all participants in the meeting and holds a single value.

    Methods

      • This method can be used to retrieve the value associated with a given key.

      Returns Promise<string>

      A promise that resolves to the stored value.

      Throws an error if the key does not exist or the request fails.

      import { useRealtimeStore } from "@videosdk.live/react-sdk";

      const key = "BLOCKED_STUDENTS";

      const { getValue } = useRealtimeStore(key);

      async function handleGetValue() {
      try {
      const value = await getValue();
      console.log("Fetched value:", value);
      } catch (error) {
      console.error("Error while getting value:", error);
      }
      }

      handleGetValue();
      • This method can be used to store or update a value in the Realtime Store.

      • If the specified key already exists, its value is overwritten. Passing null as the value deletes the key from the store.

      Parameters

      • value: string

        The value to store. Pass null to delete the key.

      Returns Promise<any>

      Throws an error if:

      • The key is missing or invalid.
      • The value is not a string or exceeds the allowed size (1 KB).
      • The request fails.
      import { useRealtimeStore } from "@videosdk.live/react-sdk";

      const key = "BLOCKED_STUDENTS";

      const { setValue } = useRealtimeStore(key);

      async function handleSetValue() {
      try {
      await setValue("[abcd, efgh]");
      console.log("Value updated successfully");
      } catch (error) {
      console.error("Error while setting value:", error);
      }
      }

      handleSetValue();

    Events

      • Triggered when the value associated with the specified key is updated in the Realtime Store by any participant.

      Parameters

      • option: { updatedBy: string; value: string }
        • updatedBy: string

          Participant ID of the user who updated the value.

        • value: string

          The latest value stored for the key.

      Returns void

      import { useRealtimeStore } from "@videosdk.live/react-sdk";

      const key = "BLOCKED_STUDENTS";

      function onValueChanged({ updatedBy, value }) {
      console.log("Value updated by:", updatedBy, "New value:", value);
      }

      useRealtimeStore(key, {
      onValueChanged,
      });