Skip to content

Commit db756c3

Browse files
Revert "specific usePropsFor to treeshake out unncessary calling/chat code (#…" (#5728)
This reverts commit 33321e6.
1 parent 05d29fc commit db756c3

8 files changed

+6
-103
lines changed

change-beta/@azure-communication-react-2e4a29d5-272c-4225-9f4f-add54c5646f1.json

-9
This file was deleted.

change-beta/@azure-communication-react-4a805157-c696-47df-8490-c10e6c9370f2.json

-9
This file was deleted.

change-beta/@azure-communication-react-bc219d8c-b452-49b5-b84d-fda5e16c9e1f.json

-9
This file was deleted.

change/@azure-communication-react-2e4a29d5-272c-4225-9f4f-add54c5646f1.json

-9
This file was deleted.

packages/communication-react/review/beta/communication-react.api.md

-6
Original file line numberDiff line numberDiff line change
@@ -5494,15 +5494,9 @@ export const useCallAgent: () => CallAgent | undefined;
54945494
// @public
54955495
export const useCallClient: () => StatefulCallClient;
54965496

5497-
// @public
5498-
export const useCallingPropsFor: <Component extends (props: any) => JSX.Element>(component: Component) => ComponentProps<Component>;
5499-
55005497
// @public
55015498
export const useChatClient: () => StatefulChatClient;
55025499

5503-
// @public
5504-
export const useChatPropsFor: <Component extends (props: any) => JSX.Element>(component: Component) => ComponentProps<Component>;
5505-
55065500
// @public
55075501
export const useChatThreadClient: () => ChatThreadClient;
55085502

packages/communication-react/review/stable/communication-react.api.md

-6
Original file line numberDiff line numberDiff line change
@@ -4743,15 +4743,9 @@ export const useCallAgent: () => CallAgent | undefined;
47434743
// @public
47444744
export const useCallClient: () => StatefulCallClient;
47454745

4746-
// @public
4747-
export const useCallingPropsFor: <Component extends (props: any) => JSX.Element>(component: Component) => ComponentProps<Component>;
4748-
47494746
// @public
47504747
export const useChatClient: () => StatefulChatClient;
47514748

4752-
// @public
4753-
export const useChatPropsFor: <Component extends (props: any) => JSX.Element>(component: Component) => ComponentProps<Component>;
4754-
47554749
// @public
47564750
export const useChatThreadClient: () => ChatThreadClient;
47574751

packages/communication-react/src/mergedHooks.ts

+6-50
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import {
55
getCallingSelector,
66
GetCallingSelector,
77
useCallingHandlers,
8-
useCallingSelector,
9-
useCallingPropsFor as useCallingPropsForInternal
8+
useCallingSelector
109
} from '@internal/calling-component-bindings';
1110
import {
1211
ChatHandlers,
1312
getChatSelector,
1413
GetChatSelector,
1514
useChatHandlers,
16-
useChatSelector,
17-
useChatPropsFor as useChatPropsForInternal
15+
useChatSelector
1816
} from '@internal/chat-component-bindings';
1917
import { ChatClientState } from '@internal/chat-stateful-client';
2018
import { CallClientState } from '@internal/calling-stateful-client';
@@ -127,63 +125,21 @@ export const usePropsFor = <Component extends (props: any) => JSX.Element>(
127125

128126
if (chatProps) {
129127
if (!chatHandlers) {
130-
throw new Error('Please initialize chatClient and chatThreadClient first!');
128+
throw 'Please initialize chatClient and chatThreadClient first!';
131129
}
132130
return { ...chatProps, ...chatHandlers } as any;
133131
}
134132

135133
if (callProps) {
136134
if (!callingHandlers) {
137-
throw new Error('Please initialize callClient first!');
135+
throw 'Please initialize callClient first!';
138136
}
139137
return { ...callProps, ...callingHandlers } as any;
140138
}
141139

142140
if (!chatSelector && !callingSelector) {
143-
throw new Error(
144-
"Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List."
145-
);
141+
throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List.";
146142
} else {
147-
throw new Error(
148-
'Could not find props for this component, ensure the component is wrapped by appropriate providers.'
149-
);
143+
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
150144
}
151145
};
152-
153-
/**
154-
* Helper function to pull the necessary properties for a chat component. There is a general usePropsFor
155-
* function however since it can pull in for both calling and chat you will not be able to leverage any treeshaking
156-
* functionality.
157-
*
158-
* @public
159-
*/
160-
export const useChatPropsFor = <Component extends (props: any) => JSX.Element>(
161-
component: Component
162-
): ComponentProps<Component> => {
163-
const props = useChatPropsForInternal(component);
164-
if (props === undefined) {
165-
throw new Error(
166-
'Could not find props for this component, ensure the component is wrapped by appropriate providers.'
167-
);
168-
}
169-
return props as ComponentProps<Component>;
170-
};
171-
172-
/**
173-
* Helper function to pull the necessary properties for a calling component. There is a general usePropsFor
174-
* function however since it can pull in for both calling and chat you will not be able to leverage any treeshaking
175-
* functionality.
176-
*
177-
* @public
178-
*/
179-
export const useCallingPropsFor = <Component extends (props: any) => JSX.Element>(
180-
component: Component
181-
): ComponentProps<Component> => {
182-
const props = useCallingPropsForInternal(component);
183-
if (props === undefined) {
184-
throw new Error(
185-
'Could not find props for this component, ensure the component is wrapped by appropriate providers.'
186-
);
187-
}
188-
return props as ComponentProps<Component>;
189-
};

packages/storybook8/stories/StatefulClient/BestPractices.mdx

-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ By using the stateful client for calling or chat, you are on our recommended pat
1717
If you are using our provided UI Components, `usePropsFor` will help you get integrated with the underlying functionality quickly. This provides a series of properties our
1818
provided components are expecting from the stateful client to render an experience your users will be expecting. This is the fastest way to get your experience up and running with Azure Communication Services.
1919

20-
If you are building calling specific or chat specific scenarios it may be advantageous to use the `useCallingPropsFor` or `useChatPropsFor` functions instead of `usePropsFor`.
21-
Since `usePropsFor` can grab references to calling or chat components it tells the treeshaking process I am going to need both Calling and Chat functionality and will not treeshake out those dependencies.
22-
If you are looking to reduce the bundle size further and you are building a chat scenario we would recommend using `useChatPropsFor` instead of `usePropsFor` and skip pulling in any calling dependencies.
23-
Similarly for calling scenarios you will want to use `useCallingPropsFor` and treeshake out any chat specific dependencies.
24-
2520
## You can use your own UI Components
2621

2722
Today you can use `useSelector` to connect your own components to create your own experiences! We use `useSelector` under the hood when you leverage our `usePropsFor` hook.

0 commit comments

Comments
 (0)