Skip to content

Commit

Permalink
chore: replace JSX.Element with ReactNode type (#2645)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela authored Feb 13, 2025
1 parent 88b6dc8 commit f00ee41
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/components/ChannelList/ChannelList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
import clsx from 'clsx';

import { ChannelListMessenger, ChannelListMessengerProps } from './ChannelListMessenger';
Expand Down Expand Up @@ -97,7 +97,7 @@ export type ChannelListProps<
t: TranslationContextValue['t'],
userLanguage: TranslationContextValue['userLanguage'],
isMessageAIGenerated?: ChatContextValue['isMessageAIGenerated'],
) => string | JSX.Element;
) => ReactNode;
/** Custom UI component to display the container for the queried channels, defaults to and accepts same props as: [ChannelListMessenger](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelList/ChannelListMessenger.tsx) */
List?: React.ComponentType<ChannelListMessengerProps<StreamChatGenerics>>;
/** Custom UI component to display the loading error indicator, defaults to component that renders null */
Expand Down
8 changes: 4 additions & 4 deletions src/components/ChannelPreview/ChannelPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import throttle from 'lodash.throttle';
import React, { useEffect, useMemo, useState } from 'react';
import React, { ReactNode, useEffect, useMemo, useState } from 'react';

import { ChannelPreviewMessenger } from './ChannelPreviewMessenger';
import { useIsChannelMuted } from './hooks/useIsChannelMuted';
Expand Down Expand Up @@ -33,9 +33,9 @@ export type ChannelPreviewUIComponentProps<
/** The last message received in a channel */
lastMessage?: StreamMessage<StreamChatGenerics>;
/** @deprecated Use latestMessagePreview prop instead. */
latestMessage?: string | JSX.Element;
latestMessage?: ReactNode;
/** Latest message preview to display, will be a string or JSX element supporting markdown. */
latestMessagePreview?: string | JSX.Element;
latestMessagePreview?: ReactNode;
/** Status describing whether own message has been delivered or read by another. If the last message is not an own message, then the status is undefined. */
messageDeliveryStatus?: MessageDeliveryStatus;
/** Number of unread Messages */
Expand All @@ -62,7 +62,7 @@ export type ChannelPreviewProps<
channel: Channel<StreamChatGenerics>,
t: TranslationContextValue['t'],
userLanguage: TranslationContextValue['userLanguage'],
) => string | JSX.Element;
) => ReactNode;
key?: string;
/** Custom ChannelPreview click handler function */
onSelect?: (event: React.MouseEvent) => void;
Expand Down
12 changes: 6 additions & 6 deletions src/components/ChannelPreview/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ReactNode } from 'react';

import ReactMarkdown from 'react-markdown';

Expand Down Expand Up @@ -37,7 +37,7 @@ export const getLatestMessagePreview = <
t: TranslationContextValue['t'],
userLanguage: TranslationContextValue['userLanguage'] = 'en',
isMessageAIGenerated?: ChatContextValue<StreamChatGenerics>['isMessageAIGenerated'],
): string | JSX.Element => {
): ReactNode => {
const latestMessage =
channel.state.latestMessages[channel.state.latestMessages.length - 1];

Expand All @@ -47,11 +47,11 @@ export const getLatestMessagePreview = <
const poll = latestMessage?.poll;

if (!latestMessage) {
return t('Nothing yet...');
return t<string>('Nothing yet...');
}

if (latestMessage.deleted_at) {
return t('Message deleted');
return t<string>('Message deleted');
}

if (poll) {
Expand Down Expand Up @@ -94,10 +94,10 @@ export const getLatestMessagePreview = <
}

if (latestMessage.attachments?.length) {
return t('🏙 Attachment...');
return t<string>('🏙 Attachment...');
}

return t('Empty message...');
return t<string>('Empty message...');
};

export type GroupChannelDisplayInfo = { image?: string; name?: string }[];
Expand Down
3 changes: 2 additions & 1 deletion src/components/Message/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TFunction } from 'i18next';
import type { ReactNode } from 'react';
import type { ReactionSort, UserResponse } from 'stream-chat';

import type { PinPermissions, UserEventHandler } from './hooks';
Expand Down Expand Up @@ -109,7 +110,7 @@ export type MessageProps<
text?: string,
mentioned_users?: UserResponse<StreamChatGenerics>[],
options?: RenderTextOptions,
) => JSX.Element | null;
) => ReactNode;
/** Custom retry send message handler to override default in [ChannelActionContext](https://getstream.io/chat/docs/sdk/react/contexts/channel_action_context/) */
retrySendMessage?: ChannelActionContextValue<StreamChatGenerics>['retrySendMessage'];
/** Comparator function to sort the list of reacted users
Expand Down
4 changes: 2 additions & 2 deletions src/context/MessageContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropsWithChildren, useContext } from 'react';
import React, { PropsWithChildren, ReactNode, useContext } from 'react';

import type { Mute, ReactionResponse, ReactionSort, UserResponse } from 'stream-chat';

Expand Down Expand Up @@ -130,7 +130,7 @@ export type MessageContextValue<
text?: string,
mentioned_users?: UserResponse<StreamChatGenerics>[],
options?: RenderTextOptions,
) => JSX.Element | null;
) => ReactNode;
/** Comparator function to sort the list of reacted users
* @deprecated use `reactionDetailsSort` instead
*/
Expand Down

0 comments on commit f00ee41

Please sign in to comment.