-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRevalidateCacheButton.tsx
More file actions
51 lines (47 loc) · 1.24 KB
/
RevalidateCacheButton.tsx
File metadata and controls
51 lines (47 loc) · 1.24 KB
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
'use client';
import { useState, useTransition } from 'react';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Typography from '@mui/material/Typography';
import { revalidateFeedCache } from '../actions';
interface Props {
feedId: string;
}
export default function RevalidateCacheButton({
feedId,
}: Props): React.ReactElement {
const [isPending, startTransition] = useTransition();
const [result, setResult] = useState<{
ok: boolean;
message: string;
} | null>(null);
const handleClick = (): void => {
setResult(null);
startTransition(async () => {
const res = await revalidateFeedCache(feedId);
setResult(res);
});
};
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 1,
width: 'fit-content',
}}
>
<Button variant='contained' onClick={handleClick} disabled={isPending}>
{isPending ? 'Revalidating…' : 'Revalidate The Cache of This Page'}
</Button>
{result != null && !isPending && (
<Typography
variant='caption'
color={result.ok ? 'success.main' : 'error.main'}
>
{result.message}
</Typography>
)}
</Box>
);
}