-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathLoadMoreButton.tsx
51 lines (45 loc) · 1.76 KB
/
LoadMoreButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { PropsWithChildren, useEffect } from 'react';
import { LoadingIndicator } from '../Loading';
import { deprecationAndReplacementWarning } from '../../utils/deprecationWarning';
import { useTranslationContext } from '../../context';
export type LoadMoreButtonProps = {
/** onClick handler load more button. Pagination logic should be executed in this handler. */
onClick: React.MouseEventHandler<HTMLButtonElement>;
/** indicates whether a loading request is in progress */
isLoading?: boolean;
/**
* @desc If true, LoadingIndicator is displayed instead of button
* @deprecated Use loading prop instead of refreshing. Planned for removal: https://github.com/GetStream/stream-chat-react/issues/1804
*/
refreshing?: boolean;
};
const UnMemoizedLoadMoreButton = ({
children,
isLoading,
onClick,
refreshing,
}: PropsWithChildren<LoadMoreButtonProps>) => {
const { t } = useTranslationContext('UnMemoizedLoadMoreButton');
const childrenOrDefaultString = children ?? t<string>('Load more');
const loading = typeof isLoading !== 'undefined' ? isLoading : refreshing;
useEffect(() => {
deprecationAndReplacementWarning([[{ refreshing }, { isLoading }]], 'LoadMoreButton');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<div className='str-chat__load-more-button'>
<button
aria-label={t('aria/Load More Channels')}
className='str-chat__load-more-button__button str-chat__cta-button'
data-testid='load-more-button'
disabled={loading}
onClick={onClick}
>
{loading ? <LoadingIndicator /> : childrenOrDefaultString}
</button>
</div>
);
};
export const LoadMoreButton = React.memo(
UnMemoizedLoadMoreButton,
) as typeof UnMemoizedLoadMoreButton;