Skip to content

Commit 6b053f5

Browse files
committed
chore: remove with*Context HOC wrappers
1 parent 17a4cb1 commit 6b053f5

8 files changed

Lines changed: 2 additions & 168 deletions

src/context/ChannelActionContext.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {
1414
import type { ChannelStateReducerAction } from '../components/Channel/channelState';
1515
import type { CustomMentionHandler } from '../components/Message/hooks/useMentionsHandler';
1616

17-
import type { ChannelUnreadUiState, UnknownType } from '../types/types';
17+
import type { ChannelUnreadUiState } from '../types/types';
1818

1919
export type MarkReadWrapperOptions = {
2020
/**
@@ -97,28 +97,3 @@ export const useChannelActionContext = (componentName?: string) => {
9797

9898
return contextValue as unknown as ChannelActionContextValue;
9999
};
100-
101-
/**
102-
* Typescript currently does not support partial inference, so if ChannelActionContext
103-
* typing is desired while using the HOC withChannelActionContext, the Props for the
104-
* wrapped component must be provided as the first generic.
105-
*/
106-
export const withChannelActionContext = <P extends UnknownType>(
107-
Component: React.ComponentType<P>,
108-
) => {
109-
const WithChannelActionContextComponent = (
110-
props: Omit<P, keyof ChannelActionContextValue>,
111-
) => {
112-
const channelActionContext = useChannelActionContext();
113-
114-
return <Component {...(props as P)} {...channelActionContext} />;
115-
};
116-
117-
WithChannelActionContextComponent.displayName = (
118-
Component.displayName ||
119-
Component.name ||
120-
'Component'
121-
).replace('Base', '');
122-
123-
return WithChannelActionContextComponent;
124-
};

src/context/ChannelStateContext.tsx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
import type {
1313
ChannelUnreadUiState,
1414
ImageAttachmentSizeHandler,
15-
UnknownType,
1615
VideoAttachmentSizeHandler,
1716
} from '../types/types';
1817

@@ -87,28 +86,3 @@ export const useChannelStateContext = (componentName?: string) => {
8786

8887
return contextValue as unknown as ChannelStateContextValue;
8988
};
90-
91-
/**
92-
* Typescript currently does not support partial inference, so if ChannelStateContext
93-
* typing is desired while using the HOC withChannelStateContext, the Props for the
94-
* wrapped component must be provided as the first generic.
95-
*/
96-
export const withChannelStateContext = <P extends UnknownType>(
97-
Component: React.ComponentType<P>,
98-
) => {
99-
const WithChannelStateContextComponent = (
100-
props: Omit<P, keyof ChannelStateContextValue>,
101-
) => {
102-
const channelStateContext = useChannelStateContext();
103-
104-
return <Component {...(props as P)} {...channelStateContext} />;
105-
};
106-
107-
WithChannelStateContextComponent.displayName = (
108-
Component.displayName ||
109-
Component.name ||
110-
'Component'
111-
).replace('Base', '');
112-
113-
return WithChannelStateContextComponent;
114-
};

src/context/ChatContext.tsx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import type {
77
SearchController,
88
} from 'stream-chat';
99

10-
import { getDisplayName } from './utils/getDisplayName';
1110
import type { ChatProps } from '../components/Chat/Chat';
12-
import type { UnknownType } from '../types/types';
1311
import type { ChannelsQueryState } from '../components/Chat/hooks/useChannelsQueryState';
1412

1513
type CSSClasses =
@@ -90,20 +88,3 @@ export const useChatContext = (componentName?: string) => {
9088

9189
return contextValue as unknown as ChatContextValue;
9290
};
93-
94-
/**
95-
* Typescript currently does not support partial inference so if ChatContext
96-
* typing is desired while using the HOC withChatContext the Props for the
97-
* wrapped component must be provided as the first generic.
98-
*/
99-
export const withChatContext = <P extends UnknownType>(
100-
Component: React.ComponentType<P>,
101-
) => {
102-
const WithChatContextComponent = (props: Omit<P, keyof ChatContextValue>) => {
103-
const chatContext = useChatContext();
104-
105-
return <Component {...(props as P)} {...chatContext} />;
106-
};
107-
WithChatContextComponent.displayName = `WithChatContext${getDisplayName(Component)}`;
108-
return WithChatContextComponent;
109-
};

src/context/ComponentContext.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import type {
6767
SearchSourceResultListProps,
6868
} from '../experimental';
6969

70-
import type { PropsWithChildrenOnly, UnknownType } from '../types/types';
70+
import type { PropsWithChildrenOnly } from '../types/types';
7171
import type { StopAIGenerationButtonProps } from '../components/MessageInput/StopAIGenerationButton';
7272
import type { ShareLocationDialogProps } from '../components/Location';
7373
import type { VideoPlayerProps } from '../components/VideoPlayer';
@@ -276,26 +276,3 @@ export const useComponentContext = (
276276
// eslint-disable-next-line @typescript-eslint/no-unused-vars
277277
_componentName?: string,
278278
) => useContext(ComponentContext) as unknown as ComponentContextValue;
279-
280-
/**
281-
* Typescript currently does not support partial inference, so if ComponentContext
282-
* typing is desired while using the HOC withComponentContext, the Props for the
283-
* wrapped component must be provided as the first generic.
284-
*/
285-
export const withComponentContext = <P extends UnknownType>(
286-
Component: React.ComponentType<P>,
287-
) => {
288-
const WithComponentContextComponent = (props: Omit<P, keyof ComponentContextValue>) => {
289-
const componentContext = useComponentContext();
290-
291-
return <Component {...(props as P)} {...componentContext} />;
292-
};
293-
294-
WithComponentContextComponent.displayName = (
295-
Component.displayName ||
296-
Component.name ||
297-
'Component'
298-
).replace('Base', '');
299-
300-
return WithComponentContextComponent;
301-
};

src/context/MessageContext.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type {
2424
} from '../components/Reactions/types';
2525

2626
import type { RenderTextOptions } from '../components/Message/renderText';
27-
import type { UnknownType } from '../types/types';
2827

2928
export type MessageContextValue = {
3029
/** If actions such as edit, delete, flag, mute are enabled on Message */
@@ -171,26 +170,3 @@ export const useMessageContext = (
171170

172171
return contextValue as unknown as MessageContextValue;
173172
};
174-
175-
/**
176-
* Typescript currently does not support partial inference, so if MessageContext
177-
* typing is desired while using the HOC withMessageContext, the Props for the
178-
* wrapped component must be provided as the first generic.
179-
*/
180-
export const withMessageContext = <P extends UnknownType>(
181-
Component: React.ComponentType<P>,
182-
) => {
183-
const WithMessageContextComponent = (props: Omit<P, keyof MessageContextValue>) => {
184-
const messageContext = useMessageContext();
185-
186-
return <Component {...(props as P)} {...messageContext} />;
187-
};
188-
189-
WithMessageContextComponent.displayName = (
190-
Component.displayName ||
191-
Component.name ||
192-
'Component'
193-
).replace('Base', '');
194-
195-
return WithMessageContextComponent;
196-
};

src/context/TranslationContext.tsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import type { PropsWithChildren } from 'react';
66
import type { TFunction } from 'i18next';
77
import type { TranslationLanguages } from 'stream-chat';
88

9-
import { getDisplayName } from './utils/getDisplayName';
109
import { defaultDateTimeParser, defaultTranslatorFunction } from '../i18n/utils';
11-
import type { UnknownType } from '../types/types';
1210
import type { TDateTimeParser } from '../i18n/types';
1311

1412
Dayjs.extend(calendar);
@@ -46,21 +44,3 @@ export const useTranslationContext = (componentName?: string) => {
4644

4745
return contextValue;
4846
};
49-
50-
export const withTranslationContext = <P extends UnknownType>(
51-
Component: React.ComponentType<P>,
52-
) => {
53-
const WithTranslationContextComponent = (
54-
props: Omit<P, keyof TranslationContextValue>,
55-
) => {
56-
const translationContext = useTranslationContext();
57-
58-
return <Component {...(props as P)} {...translationContext} />;
59-
};
60-
61-
WithTranslationContextComponent.displayName = `WithTranslationContext${getDisplayName(
62-
Component,
63-
)}`;
64-
65-
return WithTranslationContextComponent;
66-
};

src/context/TypingContext.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React, { useContext } from 'react';
22
import type { PropsWithChildren } from 'react';
33

44
import type { ChannelState as StreamChannelState } from 'stream-chat';
5-
import type { UnknownType } from '../types/types';
65

76
export type TypingContextValue = {
87
typing?: StreamChannelState['typing'];
@@ -36,26 +35,3 @@ export const useTypingContext = (componentName?: string) => {
3635

3736
return contextValue as TypingContextValue;
3837
};
39-
40-
/**
41-
* Typescript currently does not support partial inference, so if TypingContext
42-
* typing is desired while using the HOC withTypingContext, the Props for the
43-
* wrapped component must be provided as the first generic.
44-
*/
45-
export const withTypingContext = <P extends UnknownType>(
46-
Component: React.ComponentType<P>,
47-
) => {
48-
const WithTypingContextComponent = (props: Omit<P, keyof TypingContextValue>) => {
49-
const typingContext = useTypingContext();
50-
51-
return <Component {...(props as P)} {...typingContext} />;
52-
};
53-
54-
WithTypingContextComponent.displayName = (
55-
Component.displayName ||
56-
Component.name ||
57-
'Component'
58-
).replace('Base', '');
59-
60-
return WithTypingContextComponent;
61-
};

src/context/utils/getDisplayName.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)