/*! * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Microsoft Live Share SDK License. */ import { LiveState, UserMeetingRole } from "@microsoft/live-share"; import { SetLiveStateAction } from "../types/index.js"; /** * React hook for using a Live Share `LiveState`. * * @remarks * Use this hook if you want to synchronize app state that will reset when all users leave the session. * This hook can only be used in a child component of `` or ``. * * @param uniqueKey the unique key for the `LiveEvent`. If one does not yet exist, a new one will be created, otherwise it will use the existing one. * @param initialState Optional. the initial state value of type TState * @param allowedRoles Optional. the user roles that are allowed to mutate the synchronized state * @returns ordered values: first value is the synchronized state value and the second is a setter to change the state value. * The setter returns a void promise, which will throw if the user does not have the required roles to set. * * @example ```jsx import { useLiveState } from "@microsoft/live-share-react"; const planets = [ "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", ]; // Define a unique key that differentiates this usage of `useLiveState` from others in your app const MY_UNIQUE_KEY = "selected-planet-key"; // Example component for using useLiveState export const MyCustomState = () => { const [planet, setPlanet, liveState] = useLiveState(MY_UNIQUE_KEY, planets[0]); // Render loading UI when creating LiveState instance for first time if (!liveState) return <>Loading...; // Render UI return (
{`Current planet: ${planet}`} {"Select a planet below:"} {planets.map((planet) => ( ))}
); }; ``` */ export declare function useLiveState(uniqueKey: string, initialState: TState, allowedRoles?: UserMeetingRole[]): [TState, SetLiveStateAction, LiveState | undefined]; //# sourceMappingURL=useLiveState.d.ts.map