Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft of modality specific usePropsFor functions #5684

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an error like this is there a link we can provide to storybook?

} 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>(
Copy link
Member

@JamesBurnside JamesBurnside Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of recreating these in the mergedHooks, reexport them in the index.ts directly from the packlets

export { usePropsFor as useCallingPropsFor, getSelector as getCallingSelector } from './hooks/usePropsFor';

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.';
}
};
Loading