Skip to content

Commit 7e9e571

Browse files
Merge branch 'main' into vhuseinova/axios-issue-fix
2 parents 2648198 + 33321e6 commit 7e9e571

8 files changed

+103
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "patch",
3+
"area": "fix",
4+
"workstream": "fixes treeshaking issue with usePropsFor by supporting useChatPropsFor and useCallingPropsFor",
5+
"comment": "re-exporting functions and handling undefined case to match top-level usePropsFor function",
6+
"packageName": "@azure/communication-react",
7+
"email": "[email protected]",
8+
"dependentChangeType": "patch"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "prerelease",
3+
"area": "improvement",
4+
"workstream": "3",
5+
"comment": "draft of modality specific usePropsFor functions",
6+
"packageName": "@azure/communication-react",
7+
"email": "[email protected]",
8+
"dependentChangeType": "patch"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "prerelease",
3+
"area": "improvement",
4+
"workstream": "Created modality specific selectors",
5+
"comment": "draft of modality specific usePropsFor functions",
6+
"packageName": "@azure/communication-react",
7+
"email": "[email protected]",
8+
"dependentChangeType": "patch"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "patch",
3+
"area": "fix",
4+
"workstream": "fixes treeshaking issue with usePropsFor by supporting useChatPropsFor and useCallingPropsFor",
5+
"comment": "re-exporting functions and handling undefined case to match top-level usePropsFor function",
6+
"packageName": "@azure/communication-react",
7+
"email": "[email protected]",
8+
"dependentChangeType": "patch"
9+
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -5494,9 +5494,15 @@ 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+
54975500
// @public
54985501
export const useChatClient: () => StatefulChatClient;
54995502

5503+
// @public
5504+
export const useChatPropsFor: <Component extends (props: any) => JSX.Element>(component: Component) => ComponentProps<Component>;
5505+
55005506
// @public
55015507
export const useChatThreadClient: () => ChatThreadClient;
55025508

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

+6
Original file line numberDiff line numberDiff line change
@@ -4743,9 +4743,15 @@ 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+
47464749
// @public
47474750
export const useChatClient: () => StatefulChatClient;
47484751

4752+
// @public
4753+
export const useChatPropsFor: <Component extends (props: any) => JSX.Element>(component: Component) => ComponentProps<Component>;
4754+
47494755
// @public
47504756
export const useChatThreadClient: () => ChatThreadClient;
47514757

packages/communication-react/src/mergedHooks.ts

+50-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import {
55
getCallingSelector,
66
GetCallingSelector,
77
useCallingHandlers,
8-
useCallingSelector
8+
useCallingSelector,
9+
useCallingPropsFor as useCallingPropsForInternal
910
} from '@internal/calling-component-bindings';
1011
import {
1112
ChatHandlers,
1213
getChatSelector,
1314
GetChatSelector,
1415
useChatHandlers,
15-
useChatSelector
16+
useChatSelector,
17+
useChatPropsFor as useChatPropsForInternal
1618
} from '@internal/chat-component-bindings';
1719
import { ChatClientState } from '@internal/chat-stateful-client';
1820
import { CallClientState } from '@internal/calling-stateful-client';
@@ -125,21 +127,63 @@ export const usePropsFor = <Component extends (props: any) => JSX.Element>(
125127

126128
if (chatProps) {
127129
if (!chatHandlers) {
128-
throw 'Please initialize chatClient and chatThreadClient first!';
130+
throw new Error('Please initialize chatClient and chatThreadClient first!');
129131
}
130132
return { ...chatProps, ...chatHandlers } as any;
131133
}
132134

133135
if (callProps) {
134136
if (!callingHandlers) {
135-
throw 'Please initialize callClient first!';
137+
throw new Error('Please initialize callClient first!');
136138
}
137139
return { ...callProps, ...callingHandlers } as any;
138140
}
139141

140142
if (!chatSelector && !callingSelector) {
141-
throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List.";
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+
);
142146
} else {
143-
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
147+
throw new Error(
148+
'Could not find props for this component, ensure the component is wrapped by appropriate providers.'
149+
);
144150
}
145151
};
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,6 +17,11 @@ 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+
2025
## You can use your own UI Components
2126

2227
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)