UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

80 lines (76 loc) 1.8 kB
import { useMemo } from 'react'; import type { ChannelsContextValue } from '../../../contexts/channelsContext/ChannelsContext'; export const useCreateChannelsContext = ({ additionalFlatListProps, channelListInitialized, channels, error, forceUpdate, hasNextPage, loadingChannels, loadingNextPage, loadMoreThreshold, loadNextPage, maxUnreadCount, numberOfSkeletons, onSelect, getChannelActionItems, swipeActionsEnabled, refreshing, refreshList, reloadList, setFlatListRef, mutedStatusPosition, pinnedStatusPosition, }: ChannelsContextValue) => { const channelValueString = channels ?.map( (channel) => `${channel.data?.name ?? ''}${channel.id ?? ''}${ channel?.state?.unreadCount ?? '' }${Object.values(channel.state.members) .map((member) => member.user?.online) .join()}`, ) .join(); const channelsContext: ChannelsContextValue = useMemo( () => ({ additionalFlatListProps, channelListInitialized, channels, error, forceUpdate, hasNextPage, loadingChannels, loadingNextPage, loadMoreThreshold, loadNextPage, maxUnreadCount, numberOfSkeletons, onSelect, getChannelActionItems, swipeActionsEnabled, refreshing, refreshList, reloadList, setFlatListRef, mutedStatusPosition, pinnedStatusPosition, }), // eslint-disable-next-line react-hooks/exhaustive-deps [ channelValueString, error, forceUpdate, hasNextPage, loadingChannels, loadingNextPage, channelListInitialized, swipeActionsEnabled, refreshing, mutedStatusPosition, pinnedStatusPosition, ], ); return channelsContext; };