Skip to content

Commit f00ee41

Browse files
authored
chore: replace JSX.Element with ReactNode type (#2645)
1 parent 88b6dc8 commit f00ee41

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

src/components/ChannelList/ChannelList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useRef, useState } from 'react';
1+
import React, { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
22
import clsx from 'clsx';
33

44
import { ChannelListMessenger, ChannelListMessengerProps } from './ChannelListMessenger';
@@ -97,7 +97,7 @@ export type ChannelListProps<
9797
t: TranslationContextValue['t'],
9898
userLanguage: TranslationContextValue['userLanguage'],
9999
isMessageAIGenerated?: ChatContextValue['isMessageAIGenerated'],
100-
) => string | JSX.Element;
100+
) => ReactNode;
101101
/** 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) */
102102
List?: React.ComponentType<ChannelListMessengerProps<StreamChatGenerics>>;
103103
/** Custom UI component to display the loading error indicator, defaults to component that renders null */

src/components/ChannelPreview/ChannelPreview.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import throttle from 'lodash.throttle';
2-
import React, { useEffect, useMemo, useState } from 'react';
2+
import React, { ReactNode, useEffect, useMemo, useState } from 'react';
33

44
import { ChannelPreviewMessenger } from './ChannelPreviewMessenger';
55
import { useIsChannelMuted } from './hooks/useIsChannelMuted';
@@ -33,9 +33,9 @@ export type ChannelPreviewUIComponentProps<
3333
/** The last message received in a channel */
3434
lastMessage?: StreamMessage<StreamChatGenerics>;
3535
/** @deprecated Use latestMessagePreview prop instead. */
36-
latestMessage?: string | JSX.Element;
36+
latestMessage?: ReactNode;
3737
/** Latest message preview to display, will be a string or JSX element supporting markdown. */
38-
latestMessagePreview?: string | JSX.Element;
38+
latestMessagePreview?: ReactNode;
3939
/** 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. */
4040
messageDeliveryStatus?: MessageDeliveryStatus;
4141
/** Number of unread Messages */
@@ -62,7 +62,7 @@ export type ChannelPreviewProps<
6262
channel: Channel<StreamChatGenerics>,
6363
t: TranslationContextValue['t'],
6464
userLanguage: TranslationContextValue['userLanguage'],
65-
) => string | JSX.Element;
65+
) => ReactNode;
6666
key?: string;
6767
/** Custom ChannelPreview click handler function */
6868
onSelect?: (event: React.MouseEvent) => void;

src/components/ChannelPreview/utils.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { ReactNode } from 'react';
22

33
import ReactMarkdown from 'react-markdown';
44

@@ -37,7 +37,7 @@ export const getLatestMessagePreview = <
3737
t: TranslationContextValue['t'],
3838
userLanguage: TranslationContextValue['userLanguage'] = 'en',
3939
isMessageAIGenerated?: ChatContextValue<StreamChatGenerics>['isMessageAIGenerated'],
40-
): string | JSX.Element => {
40+
): ReactNode => {
4141
const latestMessage =
4242
channel.state.latestMessages[channel.state.latestMessages.length - 1];
4343

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

4949
if (!latestMessage) {
50-
return t('Nothing yet...');
50+
return t<string>('Nothing yet...');
5151
}
5252

5353
if (latestMessage.deleted_at) {
54-
return t('Message deleted');
54+
return t<string>('Message deleted');
5555
}
5656

5757
if (poll) {
@@ -94,10 +94,10 @@ export const getLatestMessagePreview = <
9494
}
9595

9696
if (latestMessage.attachments?.length) {
97-
return t('🏙 Attachment...');
97+
return t<string>('🏙 Attachment...');
9898
}
9999

100-
return t('Empty message...');
100+
return t<string>('Empty message...');
101101
};
102102

103103
export type GroupChannelDisplayInfo = { image?: string; name?: string }[];

src/components/Message/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { TFunction } from 'i18next';
2+
import type { ReactNode } from 'react';
23
import type { ReactionSort, UserResponse } from 'stream-chat';
34

45
import type { PinPermissions, UserEventHandler } from './hooks';
@@ -109,7 +110,7 @@ export type MessageProps<
109110
text?: string,
110111
mentioned_users?: UserResponse<StreamChatGenerics>[],
111112
options?: RenderTextOptions,
112-
) => JSX.Element | null;
113+
) => ReactNode;
113114
/** Custom retry send message handler to override default in [ChannelActionContext](https://getstream.io/chat/docs/sdk/react/contexts/channel_action_context/) */
114115
retrySendMessage?: ChannelActionContextValue<StreamChatGenerics>['retrySendMessage'];
115116
/** Comparator function to sort the list of reacted users

src/context/MessageContext.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { PropsWithChildren, useContext } from 'react';
1+
import React, { PropsWithChildren, ReactNode, useContext } from 'react';
22

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

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

0 commit comments

Comments
 (0)