Skip to content

Commit

Permalink
draft of modality specific usePropsFor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
alkwa-msft committed Mar 5, 2025
1 parent 2cd5e81 commit 8e015e6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/communication-react/src/mergedHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,45 @@ export const usePropsFor = <Component extends (props: any) => JSX.Element>(
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
}
};

export const useChatPropsFor = <Component extends (props: any) => JSX.Element>(
component: Component
): ComponentProps<Component> => {
const chatSelector = getChatSelector(component);
const chatProps = useChatSelector(chatSelector);
const chatHandlers = useChatHandlers<Parameters<Component>[0]>(component);

if (chatProps) {
if (!chatHandlers) {
throw 'Please initialize chatClient and chatThreadClient first!';
}
return { ...chatProps, ...chatHandlers } as any;
}

if (!chatSelector) {
throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List.";
} else {
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
}
};

export const useCallingPropsFor = <Component extends (props: any) => JSX.Element>(
component: Component
): ComponentProps<Component> => {
const callingSelector = getCallingSelector(component);
const callProps = useCallingSelector(callingSelector);
const callingHandlers = useCallingHandlers<Parameters<Component>[0]>(component);

if (callProps) {
if (!callingHandlers) {
throw 'Please initialize callClient first!';
}
return { ...callProps, ...callingHandlers } as any;
}

if (!callingSelector) {
throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List.";
} else {
throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.';
}
};

0 comments on commit 8e015e6

Please sign in to comment.