Refresh
<RefreshButton>
uses Ant Design's <Button>
component to update the data shown on the page via the useOne
method provided by your dataProvider
.
Usage
import {
RefreshButton,
useShow,
Show,
Typography,
} from "@pankod/refine";
const { Title, Text } = Typography;
export const PostShow: React.FC = () => {
const { queryResult } = useShow<IPost>();
const { data, isLoading } = queryResult;
const record = data?.data;
return (
<Show
isLoading={isLoading}
pageHeaderProps={{ extra: <RefreshButton /> }}
>
<Title level={5}>Id</Title>
<Text>{record?.id}</Text>
<Title level={5}>Title</Title>
<Text>{record?.title}</Text>
</Show>
);
};
interface IPost {
id: string;
title: string;
}
Will Look like this:
Properties
recordItemId
recordItemId
allows us to manage which data is going to be refreshed.
import { RefreshButton } from "@pankod/refine";
export const MyRefreshComponent = () => {
return <RefreshButton resourceName="posts" recordItemId="1" />;
};
Clicking the button will trigger the useOne
method and then fetches the record whose resource is "post" and whose id is "1".
<RefreshButton>
component reads the id information from the route by default.
resourceName
resourceName
allows us to manage which resource is going to be refreshed.
import { RefreshButton } from "@pankod/refine";
export const MyRefreshComponent = () => {
return <RefreshButton resourceName="categories" recordItemId="2" />;
};
Clicking the button will trigger the useOne
method and then fetches the record whose resource is "categories" and whose id is "2".
<RefreshButton>
component reads the resource name from the route by default.
hideText
It is used to show and not show the text of the button. When true
, only the button icon is visible.
import { RefreshButton } from "@pankod/refine";
export const MyRefreshComponent = () => {
return <RefreshButton hideText />;
};
API Reference
Properties
Property | Description | Type | Default |
---|---|---|---|
props | Ant Design button props | ButtonProps & { resourceName?: string; recordItemId?: string; hideText?: boolean; } | |
resourceName | Determines which resource to use for refresh | string | Resource name that it reads from route |
recordItemId | Determines which id to use for refresh | string | Record id that it reads from route |
hideText | Allows to hide button text | boolean | false |
children | Sets the button text | ReactNode | "Refresh" |
icon | Sets the icon component of button | ReactNode | <RedoOutlined /> |
onClick | Sets the handler to handle the click event | (event) => void | trigger the useOne method for refresh |
metaData | Metadata query for dataProvider | MetaDataQuery | {} |