@microsoft/live-share-react 1.3.0-preview.0 → 1.4.0-preview.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.
Files changed (53) hide show
  1. package/.nycrc.json +9 -9
  2. package/LICENSE +86 -86
  3. package/README.md +608 -608
  4. package/bin/live-hooks/useLiveEvent.d.ts.map +1 -1
  5. package/bin/live-hooks/useLiveEvent.js +6 -0
  6. package/bin/live-hooks/useLiveEvent.js.map +1 -1
  7. package/bin/live-hooks/useLiveFollowMode.d.ts.map +1 -1
  8. package/bin/live-hooks/useLiveFollowMode.js +2 -4
  9. package/bin/live-hooks/useLiveFollowMode.js.map +1 -1
  10. package/bin/live-hooks/useLivePresence.d.ts.map +1 -1
  11. package/bin/live-hooks/useLivePresence.js +1 -3
  12. package/bin/live-hooks/useLivePresence.js.map +1 -1
  13. package/bin/live-hooks/useLiveState.d.ts.map +1 -1
  14. package/bin/live-hooks/useLiveState.js +1 -3
  15. package/bin/live-hooks/useLiveState.js.map +1 -1
  16. package/bin/live-hooks/useLiveTimer.d.ts.map +1 -1
  17. package/bin/live-hooks/useLiveTimer.js +4 -0
  18. package/bin/live-hooks/useLiveTimer.js.map +1 -1
  19. package/package.json +50 -50
  20. package/src/index.ts +6 -6
  21. package/src/interfaces/LiveInterfaceExtensions.ts +26 -26
  22. package/src/interfaces/index.ts +1 -1
  23. package/src/internal/errors.ts +57 -57
  24. package/src/internal/index.ts +2 -2
  25. package/src/internal/type-guards.ts +9 -9
  26. package/src/live-hooks/index.ts +7 -7
  27. package/src/live-hooks/useLiveCanvas.ts +191 -191
  28. package/src/live-hooks/useLiveEvent.ts +146 -140
  29. package/src/live-hooks/useLiveFollowMode.ts +315 -316
  30. package/src/live-hooks/useLivePresence.ts +146 -147
  31. package/src/live-hooks/useLiveState.ts +108 -110
  32. package/src/live-hooks/useLiveTimer.ts +217 -213
  33. package/src/live-hooks/useMediaSynchronizer.ts +295 -295
  34. package/src/providers/AzureProvider.tsx +261 -261
  35. package/src/providers/LiveShareProvider.tsx +210 -210
  36. package/src/providers/index.ts +2 -2
  37. package/src/shared-hooks/index.ts +4 -4
  38. package/src/shared-hooks/useDynamicDDS.ts +82 -82
  39. package/src/shared-hooks/useSharedMap.ts +159 -159
  40. package/src/shared-hooks/useSharedState.ts +96 -96
  41. package/src/shared-hooks/useSharedStateRegistry.ts +170 -170
  42. package/src/types/ActionTypes.ts +161 -161
  43. package/src/types/PropTypes.ts +10 -10
  44. package/src/types/ResultTypes.ts +332 -332
  45. package/src/types/index.ts +3 -3
  46. package/src/utils/index.ts +1 -1
  47. package/src/utils/type-check.ts +69 -69
  48. package/tsconfig.build.json +5 -5
  49. package/tsconfig.json +72 -72
  50. package/bin/internal/useSharedStateRegistry.d.ts +0 -31
  51. package/bin/internal/useSharedStateRegistry.d.ts.map +0 -1
  52. package/bin/internal/useSharedStateRegistry.js +0 -102
  53. package/bin/internal/useSharedStateRegistry.js.map +0 -1
@@ -1,210 +1,210 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
-
6
- import { IFluidContainer, LoadableObjectClassRecord } from "fluid-framework";
7
- import React from "react";
8
- import { useSharedStateRegistry } from "../shared-hooks";
9
- import {
10
- ILiveShareClientOptions,
11
- ILiveShareHost,
12
- ILiveShareJoinResults,
13
- ITimestampProvider,
14
- } from "@microsoft/live-share";
15
- import { FluidContext, useFluidObjectsContext } from "./AzureProvider";
16
- import { LiveShareTurboClient } from "@microsoft/live-share-turbo";
17
-
18
- /**
19
- * React Context provider values for `<LiveShareProvider>`.
20
- *
21
- * @remarks
22
- * To get the latest values, use the {@link useLiveShareContext} hook.
23
- * Use the {@link useFluidObjectsContext} hook for other relevant context values.
24
- */
25
- export interface ILiveShareContext {
26
- /**
27
- * True if the local user created the Fluid container
28
- */
29
- created: boolean;
30
- /**
31
- * True if connected to the Live Share container
32
- */
33
- joined: boolean;
34
- /**
35
- * An error that will be defined if there was a problem joining the container, or undefined if not.
36
- */
37
- joinError: Error | undefined;
38
- /**
39
- * Live Share timestamp provider. Can be used to `.getTimestamp()` for a global clock value.
40
- * This reference timestamp value should be fairly consistent for all users in the session.
41
- */
42
- timestampProvider: ITimestampProvider | undefined;
43
- /**
44
- * Join callback method for manually connecting to the Fluid container.
45
- *
46
- * @remarks
47
- * Use this callback if `joinOnLoad` is `false` or `undefined` in {@link ILiveShareProviderProps}.
48
- *
49
- * @param initialObjects Optional. The initial objects for the Fluid container schema.
50
- * @param onInitializeContainer Optional. Callback for when the container is first created.
51
- * @returns Promise with `ILiveShareJoinResults`, which includes the Fluid container
52
- */
53
- join: (
54
- initialObjects?: LoadableObjectClassRecord,
55
- onInitializeContainer?: (container: IFluidContainer) => void
56
- ) => Promise<ILiveShareJoinResults>;
57
- }
58
-
59
- /**
60
- * @hidden
61
- */
62
- export const LiveShareContext = React.createContext<ILiveShareContext>(
63
- {} as ILiveShareContext
64
- );
65
-
66
- /**
67
- * Hook to get the latest React context state for `LiveShareContext`.
68
- *
69
- * @remarks
70
- * This hook can only be used in a child component of `<LiveShareProvider>`.
71
- * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
72
- *
73
- * @returns current state of `LiveShareContext`
74
- */
75
- export const useLiveShareContext = (): ILiveShareContext => {
76
- const context = React.useContext(LiveShareContext);
77
- if (!isLiveShareContext(context)) {
78
- throw new Error(
79
- "@microsoft/live-share-react: attempting to use `useLiveShareContext()` from a component that is not a child of `<LiveShareProvider>`.\nTo fix this error, ensure that you are only using Live Share hooks (e.g., `useLiveState`) from a child component of `<LiveShareProvider>`."
80
- );
81
- }
82
- return context;
83
- };
84
-
85
- /**
86
- * Prop types for {@link LiveShareProvider} component.
87
- */
88
- export interface ILiveShareProviderProps {
89
- /**
90
- * Optional. React children node for the React Context Provider
91
- */
92
- children?: React.ReactNode;
93
- /**
94
- * Optional. Options for initializing `LiveShareClient`.
95
- */
96
- clientOptions?: ILiveShareClientOptions;
97
- /**
98
- * Host to initialize `LiveShareClient` with.
99
- *
100
- * @remarks
101
- * If using the `LiveShareClient` class from `@microsoft/teams-js`, you must ensure that you have first called `teamsJs.app.initialize()` before calling `LiveShareClient.create()`.
102
- */
103
- host: ILiveShareHost;
104
- /**
105
- * The initial object schema to use when {@link joinOnLoad} is true.
106
- */
107
- initialObjects?: LoadableObjectClassRecord;
108
- /**
109
- * Optional. Flag to determine whether to join Fluid container on load.
110
- */
111
- joinOnLoad?: boolean;
112
- }
113
-
114
- /**
115
- * React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
116
- */
117
- export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
118
- const startedRef = React.useRef(false);
119
- const clientRef = React.useRef(
120
- new LiveShareTurboClient(props.host, props.clientOptions)
121
- );
122
- const [results, setResults] = React.useState<
123
- ILiveShareJoinResults | undefined
124
- >();
125
- const [joinError, setJoinError] = React.useState<Error | undefined>();
126
-
127
- const stateRegistryCallbacks = useSharedStateRegistry(results);
128
-
129
- /**
130
- * Join container callback for joining the Live Share session
131
- */
132
- const join = React.useCallback(
133
- async (
134
- initialObjects?: LoadableObjectClassRecord,
135
- onInitializeContainer?: (container: IFluidContainer) => void
136
- ): Promise<ILiveShareJoinResults> => {
137
- startedRef.current = true;
138
- const results = await clientRef.current.join(
139
- initialObjects,
140
- onInitializeContainer
141
- );
142
- setResults(results);
143
- return results;
144
- },
145
- []
146
- );
147
-
148
- /**
149
- * Joins the container on load if `props.joinOnLoad` is true
150
- */
151
- React.useEffect(() => {
152
- // This hook should only be called once, so we use a ref to track if it has been called.
153
- // This is a workaround for the fact that useEffect is called twice on initial render in React V18.
154
- // We are not doing this here for backwards compatibility. View the README for more information.
155
- if (results !== undefined || startedRef.current || !props.joinOnLoad)
156
- return;
157
- join(props.initialObjects).catch((error) => {
158
- console.error(error);
159
- if (error instanceof Error) {
160
- setJoinError(error);
161
- } else {
162
- setJoinError(
163
- new Error(
164
- "LiveShareProvider: An unknown error occurred while joining container."
165
- )
166
- );
167
- }
168
- });
169
- }, [results, props.joinOnLoad, props.initialObjects, join]);
170
-
171
- return (
172
- <LiveShareContext.Provider
173
- value={{
174
- created: !!results?.created,
175
- timestampProvider: results?.timestampProvider,
176
- joined: !!results?.container,
177
- joinError,
178
- join,
179
- }}
180
- >
181
- <FluidContext.Provider
182
- value={{
183
- clientRef,
184
- container: results?.container,
185
- services: results?.services,
186
- joinError,
187
- getContainer: async () => {
188
- throw new Error(
189
- "Cannot join new container through getContainer in LiveShareProvider"
190
- );
191
- },
192
- createContainer: async () => {
193
- throw new Error(
194
- "Cannot create new container through createContainer in LiveShareProvider"
195
- );
196
- },
197
- ...stateRegistryCallbacks,
198
- }}
199
- >
200
- {props.children}
201
- </FluidContext.Provider>
202
- </LiveShareContext.Provider>
203
- );
204
- };
205
-
206
- function isLiveShareContext(value: any): value is ILiveShareContext {
207
- return (
208
- typeof value?.created === "boolean" && typeof value?.join === "function"
209
- );
210
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ import { IFluidContainer, LoadableObjectClassRecord } from "fluid-framework";
7
+ import React from "react";
8
+ import { useSharedStateRegistry } from "../shared-hooks";
9
+ import {
10
+ ILiveShareClientOptions,
11
+ ILiveShareHost,
12
+ ILiveShareJoinResults,
13
+ ITimestampProvider,
14
+ } from "@microsoft/live-share";
15
+ import { FluidContext, useFluidObjectsContext } from "./AzureProvider";
16
+ import { LiveShareTurboClient } from "@microsoft/live-share-turbo";
17
+
18
+ /**
19
+ * React Context provider values for `<LiveShareProvider>`.
20
+ *
21
+ * @remarks
22
+ * To get the latest values, use the {@link useLiveShareContext} hook.
23
+ * Use the {@link useFluidObjectsContext} hook for other relevant context values.
24
+ */
25
+ export interface ILiveShareContext {
26
+ /**
27
+ * True if the local user created the Fluid container
28
+ */
29
+ created: boolean;
30
+ /**
31
+ * True if connected to the Live Share container
32
+ */
33
+ joined: boolean;
34
+ /**
35
+ * An error that will be defined if there was a problem joining the container, or undefined if not.
36
+ */
37
+ joinError: Error | undefined;
38
+ /**
39
+ * Live Share timestamp provider. Can be used to `.getTimestamp()` for a global clock value.
40
+ * This reference timestamp value should be fairly consistent for all users in the session.
41
+ */
42
+ timestampProvider: ITimestampProvider | undefined;
43
+ /**
44
+ * Join callback method for manually connecting to the Fluid container.
45
+ *
46
+ * @remarks
47
+ * Use this callback if `joinOnLoad` is `false` or `undefined` in {@link ILiveShareProviderProps}.
48
+ *
49
+ * @param initialObjects Optional. The initial objects for the Fluid container schema.
50
+ * @param onInitializeContainer Optional. Callback for when the container is first created.
51
+ * @returns Promise with `ILiveShareJoinResults`, which includes the Fluid container
52
+ */
53
+ join: (
54
+ initialObjects?: LoadableObjectClassRecord,
55
+ onInitializeContainer?: (container: IFluidContainer) => void
56
+ ) => Promise<ILiveShareJoinResults>;
57
+ }
58
+
59
+ /**
60
+ * @hidden
61
+ */
62
+ export const LiveShareContext = React.createContext<ILiveShareContext>(
63
+ {} as ILiveShareContext
64
+ );
65
+
66
+ /**
67
+ * Hook to get the latest React context state for `LiveShareContext`.
68
+ *
69
+ * @remarks
70
+ * This hook can only be used in a child component of `<LiveShareProvider>`.
71
+ * See `useFluidObjectsContext` for other information related to the Live Share session, such as the `container`.
72
+ *
73
+ * @returns current state of `LiveShareContext`
74
+ */
75
+ export const useLiveShareContext = (): ILiveShareContext => {
76
+ const context = React.useContext(LiveShareContext);
77
+ if (!isLiveShareContext(context)) {
78
+ throw new Error(
79
+ "@microsoft/live-share-react: attempting to use `useLiveShareContext()` from a component that is not a child of `<LiveShareProvider>`.\nTo fix this error, ensure that you are only using Live Share hooks (e.g., `useLiveState`) from a child component of `<LiveShareProvider>`."
80
+ );
81
+ }
82
+ return context;
83
+ };
84
+
85
+ /**
86
+ * Prop types for {@link LiveShareProvider} component.
87
+ */
88
+ export interface ILiveShareProviderProps {
89
+ /**
90
+ * Optional. React children node for the React Context Provider
91
+ */
92
+ children?: React.ReactNode;
93
+ /**
94
+ * Optional. Options for initializing `LiveShareClient`.
95
+ */
96
+ clientOptions?: ILiveShareClientOptions;
97
+ /**
98
+ * Host to initialize `LiveShareClient` with.
99
+ *
100
+ * @remarks
101
+ * If using the `LiveShareClient` class from `@microsoft/teams-js`, you must ensure that you have first called `teamsJs.app.initialize()` before calling `LiveShareClient.create()`.
102
+ */
103
+ host: ILiveShareHost;
104
+ /**
105
+ * The initial object schema to use when {@link joinOnLoad} is true.
106
+ */
107
+ initialObjects?: LoadableObjectClassRecord;
108
+ /**
109
+ * Optional. Flag to determine whether to join Fluid container on load.
110
+ */
111
+ joinOnLoad?: boolean;
112
+ }
113
+
114
+ /**
115
+ * React Context provider component for using Live Share data objects & joining a Live Share session using `LiveShareClient`.
116
+ */
117
+ export const LiveShareProvider: React.FC<ILiveShareProviderProps> = (props) => {
118
+ const startedRef = React.useRef(false);
119
+ const clientRef = React.useRef(
120
+ new LiveShareTurboClient(props.host, props.clientOptions)
121
+ );
122
+ const [results, setResults] = React.useState<
123
+ ILiveShareJoinResults | undefined
124
+ >();
125
+ const [joinError, setJoinError] = React.useState<Error | undefined>();
126
+
127
+ const stateRegistryCallbacks = useSharedStateRegistry(results);
128
+
129
+ /**
130
+ * Join container callback for joining the Live Share session
131
+ */
132
+ const join = React.useCallback(
133
+ async (
134
+ initialObjects?: LoadableObjectClassRecord,
135
+ onInitializeContainer?: (container: IFluidContainer) => void
136
+ ): Promise<ILiveShareJoinResults> => {
137
+ startedRef.current = true;
138
+ const results = await clientRef.current.join(
139
+ initialObjects,
140
+ onInitializeContainer
141
+ );
142
+ setResults(results);
143
+ return results;
144
+ },
145
+ []
146
+ );
147
+
148
+ /**
149
+ * Joins the container on load if `props.joinOnLoad` is true
150
+ */
151
+ React.useEffect(() => {
152
+ // This hook should only be called once, so we use a ref to track if it has been called.
153
+ // This is a workaround for the fact that useEffect is called twice on initial render in React V18.
154
+ // We are not doing this here for backwards compatibility. View the README for more information.
155
+ if (results !== undefined || startedRef.current || !props.joinOnLoad)
156
+ return;
157
+ join(props.initialObjects).catch((error) => {
158
+ console.error(error);
159
+ if (error instanceof Error) {
160
+ setJoinError(error);
161
+ } else {
162
+ setJoinError(
163
+ new Error(
164
+ "LiveShareProvider: An unknown error occurred while joining container."
165
+ )
166
+ );
167
+ }
168
+ });
169
+ }, [results, props.joinOnLoad, props.initialObjects, join]);
170
+
171
+ return (
172
+ <LiveShareContext.Provider
173
+ value={{
174
+ created: !!results?.created,
175
+ timestampProvider: results?.timestampProvider,
176
+ joined: !!results?.container,
177
+ joinError,
178
+ join,
179
+ }}
180
+ >
181
+ <FluidContext.Provider
182
+ value={{
183
+ clientRef,
184
+ container: results?.container,
185
+ services: results?.services,
186
+ joinError,
187
+ getContainer: async () => {
188
+ throw new Error(
189
+ "Cannot join new container through getContainer in LiveShareProvider"
190
+ );
191
+ },
192
+ createContainer: async () => {
193
+ throw new Error(
194
+ "Cannot create new container through createContainer in LiveShareProvider"
195
+ );
196
+ },
197
+ ...stateRegistryCallbacks,
198
+ }}
199
+ >
200
+ {props.children}
201
+ </FluidContext.Provider>
202
+ </LiveShareContext.Provider>
203
+ );
204
+ };
205
+
206
+ function isLiveShareContext(value: any): value is ILiveShareContext {
207
+ return (
208
+ typeof value?.created === "boolean" && typeof value?.join === "function"
209
+ );
210
+ }
@@ -1,2 +1,2 @@
1
- export * from "./AzureProvider";
2
- export * from "./LiveShareProvider";
1
+ export * from "./AzureProvider";
2
+ export * from "./LiveShareProvider";
@@ -1,4 +1,4 @@
1
- export * from "./useSharedState";
2
- export * from "./useSharedMap";
3
- export * from "./useDynamicDDS";
4
- export * from "./useSharedStateRegistry";
1
+ export * from "./useSharedState";
2
+ export * from "./useSharedMap";
3
+ export * from "./useDynamicDDS";
4
+ export * from "./useSharedStateRegistry";
@@ -1,82 +1,82 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
-
6
- import React from "react";
7
- import { FluidObject, IFluidLoadable } from "@fluidframework/core-interfaces";
8
- import { useFluidObjectsContext } from "../providers";
9
- import { LoadableObjectClass } from "fluid-framework";
10
-
11
- /**
12
- * Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
13
- *
14
- * @remarks
15
- * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
16
- *
17
- * @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
18
- * @param uniqueKey uniqueKey value for the data object
19
- * @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
20
- * @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
21
- * @returns the DDS object, which is of type T when loaded and undefined while loading
22
- */
23
- export function useDynamicDDS<
24
- T extends IFluidLoadable = FluidObject<any> & IFluidLoadable
25
- >(
26
- uniqueKey: string,
27
- loadableObjectClass: LoadableObjectClass<T>,
28
- onFirstInitialize?: (dds: T) => void
29
- ): {
30
- dds: T | undefined;
31
- error: Error | undefined;
32
- } {
33
- const [dds, setDDS] = React.useState<T>();
34
- const [error, setError] = React.useState<Error>();
35
- /**
36
- * Import container and DDS object register callbacks from AzureProvider.
37
- */
38
- const { container, clientRef } = useFluidObjectsContext();
39
-
40
- /**
41
- * Once container is available, this effect will register the setter method so that the DDS loaded
42
- * from `dynamicObjects` that matches `uniqueKey` can be passed back to this hook. If one does not yet exist,
43
- * a new DDS is automatically created. If multiple users try to create a DDS at the same time when this component first
44
- * mounts, `live-share-turbo` ensures it will ultimately self correct using last-writer wins.
45
- */
46
- React.useEffect(() => {
47
- if (container === undefined) return;
48
- let mounted = true;
49
- // Callback method to set the `initialData` into the map when the DDS is first created.
50
- const onGetDDS = async () => {
51
- try {
52
- const dds = await clientRef.current.getDDS<T>(
53
- uniqueKey,
54
- loadableObjectClass,
55
- onFirstInitialize
56
- );
57
- if (mounted) {
58
- setDDS(dds);
59
- }
60
- } catch (error: unknown) {
61
- if (error instanceof Error) {
62
- setError(error);
63
- } else {
64
- setError(
65
- new Error(
66
- "useDynamicDDS: an unknown error occurred while getting the DDS"
67
- )
68
- );
69
- }
70
- }
71
- };
72
- onGetDDS();
73
- return () => {
74
- mounted = false;
75
- };
76
- }, [container, uniqueKey, onFirstInitialize]);
77
-
78
- return {
79
- dds,
80
- error,
81
- };
82
- }
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ import React from "react";
7
+ import { FluidObject, IFluidLoadable } from "@fluidframework/core-interfaces";
8
+ import { useFluidObjectsContext } from "../providers";
9
+ import { LoadableObjectClass } from "fluid-framework";
10
+
11
+ /**
12
+ * Hook to gets or creates a DDS that corresponds to a given uniqueKey string.
13
+ *
14
+ * @remarks
15
+ * This hook can only be used in a child component of `<LiveShareProvider>` or `<AzureProvider>`.
16
+ *
17
+ * @template T Type of Fluid LoadableObjectClass type to load. Must conform to IFluidLoadable interface.
18
+ * @param uniqueKey uniqueKey value for the data object
19
+ * @param loadableObjectClass Fluid LoadableObjectClass<T> to create/load.
20
+ * @param onFirstInitialize Optional. Callback function for when the DDS is first loaded
21
+ * @returns the DDS object, which is of type T when loaded and undefined while loading
22
+ */
23
+ export function useDynamicDDS<
24
+ T extends IFluidLoadable = FluidObject<any> & IFluidLoadable
25
+ >(
26
+ uniqueKey: string,
27
+ loadableObjectClass: LoadableObjectClass<T>,
28
+ onFirstInitialize?: (dds: T) => void
29
+ ): {
30
+ dds: T | undefined;
31
+ error: Error | undefined;
32
+ } {
33
+ const [dds, setDDS] = React.useState<T>();
34
+ const [error, setError] = React.useState<Error>();
35
+ /**
36
+ * Import container and DDS object register callbacks from AzureProvider.
37
+ */
38
+ const { container, clientRef } = useFluidObjectsContext();
39
+
40
+ /**
41
+ * Once container is available, this effect will register the setter method so that the DDS loaded
42
+ * from `dynamicObjects` that matches `uniqueKey` can be passed back to this hook. If one does not yet exist,
43
+ * a new DDS is automatically created. If multiple users try to create a DDS at the same time when this component first
44
+ * mounts, `live-share-turbo` ensures it will ultimately self correct using last-writer wins.
45
+ */
46
+ React.useEffect(() => {
47
+ if (container === undefined) return;
48
+ let mounted = true;
49
+ // Callback method to set the `initialData` into the map when the DDS is first created.
50
+ const onGetDDS = async () => {
51
+ try {
52
+ const dds = await clientRef.current.getDDS<T>(
53
+ uniqueKey,
54
+ loadableObjectClass,
55
+ onFirstInitialize
56
+ );
57
+ if (mounted) {
58
+ setDDS(dds);
59
+ }
60
+ } catch (error: unknown) {
61
+ if (error instanceof Error) {
62
+ setError(error);
63
+ } else {
64
+ setError(
65
+ new Error(
66
+ "useDynamicDDS: an unknown error occurred while getting the DDS"
67
+ )
68
+ );
69
+ }
70
+ }
71
+ };
72
+ onGetDDS();
73
+ return () => {
74
+ mounted = false;
75
+ };
76
+ }, [container, uniqueKey, onFirstInitialize]);
77
+
78
+ return {
79
+ dds,
80
+ error,
81
+ };
82
+ }