Skip to content

Commit fd0d26d

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/alkwa/create-modality-specific-selectors' into alkwa/create-modality-specific-selectors
2 parents a6bf990 + f2b3beb commit fd0d26d

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
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": "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/src/mergedHooks.ts

+18-2
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';
@@ -148,6 +150,13 @@ export const usePropsFor = <Component extends (props: any) => JSX.Element>(
148150
}
149151
};
150152

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+
*/
151160
export const useChatPropsFor = <Component extends (props: any) => JSX.Element>(
152161
component: Component
153162
): ComponentProps<Component> => {
@@ -173,6 +182,13 @@ export const useChatPropsFor = <Component extends (props: any) => JSX.Element>(
173182
}
174183
};
175184

185+
/**
186+
* Helper function to pull the necessary properties for a calling component. There is a general usePropsFor
187+
* function however since it can pull in for both calling and chat you will not be able to leverage any treeshaking
188+
* functionality.
189+
*
190+
* @public
191+
*/
176192
export const useCallingPropsFor = <Component extends (props: any) => JSX.Element>(
177193
component: Component
178194
): ComponentProps<Component> => {

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)