Skip to content

Commit

Permalink
VIDCS-3480: forwarding ref error in console (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpettet authored Mar 3, 2025
1 parent 4062a59 commit 6aca326
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Badge } from '@mui/material';
import { ReactElement } from 'react';
import { ForwardedRef, forwardRef, ReactElement } from 'react';
import useSessionContext from '../../../hooks/useSessionContext';

export type UnreadMessagesBadgeProps = {
Expand All @@ -14,11 +14,16 @@ export type UnreadMessagesBadgeProps = {
* @property {ReactElement} children - the ToolbarButton to be rendered
* @returns {ReactElement} - The UnreadMessagesBadge component
*/
const UnreadMessagesBadge = ({ children }: UnreadMessagesBadgeProps): ReactElement => {
const UnreadMessagesBadge = forwardRef(function UnreadMessagesBadge(
props: UnreadMessagesBadgeProps,
ref: ForwardedRef<HTMLSpanElement>
) {
const { children, ...rest } = props;
const { unreadCount } = useSessionContext();

return (
<Badge
{...rest}
badgeContent={unreadCount}
data-testid="chat-button-unread-count"
invisible={unreadCount === 0}
Expand All @@ -30,10 +35,11 @@ const UnreadMessagesBadge = ({ children }: UnreadMessagesBadgeProps): ReactEleme
marginRight: '12px',
}}
overlap="circular"
ref={ref}
>
{children}
</Badge>
);
};
});

export default UnreadMessagesBadge;

0 comments on commit 6aca326

Please sign in to comment.