Skip to content

Commit 2ad6132

Browse files
authored
fix: make setChannels prop optional for ChannelSearch (#2358)
### 🎯 Goal `setChannels` is used by the `ChannelSearch` component to update the channel list state to include the selected search result. When rendered by the `ChannelList`, it actually passes its own `setChannels` setter there. But this behavior should be optional, because it's totally valid to use search outside of the `ChannelList`.
1 parent 6575d30 commit 2ad6132

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: src/components/ChannelSearch/hooks/useChannelSearch.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export type ChannelSearchControllerParams<
8585
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
8686
> = ChannelSearchParams<StreamChatGenerics> & {
8787
/** Set the array of channels displayed in the ChannelList */
88-
setChannels: React.Dispatch<React.SetStateAction<Array<Channel<StreamChatGenerics>>>>;
88+
setChannels?: React.Dispatch<React.SetStateAction<Array<Channel<StreamChatGenerics>>>>;
8989
};
9090

9191
export const useChannelSearch = <
@@ -204,7 +204,7 @@ export const useChannelSearch = <
204204
setActiveChannel(newChannel);
205205
selectedChannel = newChannel;
206206
}
207-
setChannels((channels) => uniqBy([selectedChannel, ...channels], 'cid'));
207+
setChannels?.((channels) => uniqBy([selectedChannel, ...channels], 'cid'));
208208
if (clearSearchOnClickOutside) {
209209
exitSearch();
210210
}

0 commit comments

Comments
 (0)