shlink-web-client/src/short-urls/ShortUrls.tsx

30 lines
1 KiB
TypeScript
Raw Normal View History

2020-11-14 00:44:26 +03:00
import { FC, useEffect, useState } from 'react';
2020-12-12 12:56:10 +03:00
import { Card } from 'reactstrap';
import Paginator from './Paginator';
import { ShortUrlsListProps } from './ShortUrlsList';
const ShortUrls = (SearchBar: FC, ShortUrlsList: FC<ShortUrlsListProps>) => (props: ShortUrlsListProps) => {
const { match, shortUrlsList } = props;
const { page = '1', serverId = '' } = match?.params ?? {};
const { pagination } = shortUrlsList?.shortUrls ?? {};
const [ urlsListKey, setUrlsListKey ] = useState(`${serverId}_${page}`);
// Using a key on a component makes react to create a new instance every time the key changes
// Without it, pagination on the URL will not make the component to be refreshed
useEffect(() => {
setUrlsListKey(`${serverId}_${page}`);
}, [ serverId, page ]);
return (
2020-11-14 00:44:26 +03:00
<>
<div className="form-group"><SearchBar /></div>
2020-12-12 12:56:10 +03:00
<Card body className="pb-1">
<ShortUrlsList {...props} key={urlsListKey} />
<Paginator paginator={pagination} serverId={serverId} />
2020-12-12 12:56:10 +03:00
</Card>
2020-11-14 00:44:26 +03:00
</>
);
};
export default ShortUrls;