Skip to content

Commit 8e015e6

Browse files
committed
draft of modality specific usePropsFor functions
1 parent 2cd5e81 commit 8e015e6

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/communication-react/src/mergedHooks.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,45 @@ export const usePropsFor = <Component extends (props: any) => JSX.Element>(
143143
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
144144
}
145145
};
146+
147+
export const useChatPropsFor = <Component extends (props: any) => JSX.Element>(
148+
component: Component
149+
): ComponentProps<Component> => {
150+
const chatSelector = getChatSelector(component);
151+
const chatProps = useChatSelector(chatSelector);
152+
const chatHandlers = useChatHandlers<Parameters<Component>[0]>(component);
153+
154+
if (chatProps) {
155+
if (!chatHandlers) {
156+
throw 'Please initialize chatClient and chatThreadClient first!';
157+
}
158+
return { ...chatProps, ...chatHandlers } as any;
159+
}
160+
161+
if (!chatSelector) {
162+
throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List.";
163+
} else {
164+
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
165+
}
166+
};
167+
168+
export const useCallingPropsFor = <Component extends (props: any) => JSX.Element>(
169+
component: Component
170+
): ComponentProps<Component> => {
171+
const callingSelector = getCallingSelector(component);
172+
const callProps = useCallingSelector(callingSelector);
173+
const callingHandlers = useCallingHandlers<Parameters<Component>[0]>(component);
174+
175+
if (callProps) {
176+
if (!callingHandlers) {
177+
throw 'Please initialize callClient first!';
178+
}
179+
return { ...callProps, ...callingHandlers } as any;
180+
}
181+
182+
if (!callingSelector) {
183+
throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List.";
184+
} else {
185+
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
186+
}
187+
};

0 commit comments

Comments
 (0)