Refresh
const { default: routerProvider } = LegacyRefineReactRouterV6;
const { default: simpleRest } = RefineSimpleRest;
setRefineProps({
legacyRouterProvider: routerProvider,
dataProvider: simpleRest("https://api.fake-rest.refine.dev"),
notificationProvider: RefineMantine.useNotificationProvider,
Layout: RefineMantine.Layout,
Sider: () => null,
catchAll: <RefineMantine.ErrorComponent />,
});
const Wrapper = ({ children }) => {
return (
<MantineCore.MantineProvider
theme={RefineMantine.LightTheme}
withNormalizeCSS
withGlobalStyles
>
<MantineCore.Global styles={{ body: { WebkitFontSmoothing: "auto" } }} />
<MantineNotifications.NotificationsProvider position="top-right">
{children}
</MantineNotifications.NotificationsProvider>
</MantineCore.MantineProvider>
);
};
<RefreshButton> uses Mantine <Button> omponent to update the data shown on the page via the useInvalidate hook.
You can swizzle this component with the Refine CLI to customize it.
Usage
setInitialRoutes(["/posts/show/123"]);
import { Refine } from "@refinedev/core";
import { ShowButton } from "@refinedev/mantine";
// visible-block-start
import { useShow } from "@refinedev/core";
import {
Show,
MarkdownField,
RefreshButton,
} from "@refinedev/mantine";
import { Title, Text } from "@mantine/core";
const PostShow: React.FC = () => {
const { queryResult } = useShow<IPost>();
const { data, isLoading } = queryResult;
const record = data?.data;
return (
<Show headerButtons={<RefreshButton />} isLoading={isLoading}>
<Title order={5}>Id</Title>
<Text mt="sm">{record?.id}</Text>
<Title mt="sm" order={5}>
Title
</Title>
<Text mt="sm">{record?.title}</Text>
<Title mt="sm" order={5}>
Content
</Title>
<MarkdownField value={record?.content} />
</Show>
);
};
// visible-block-end
const App = () => {
return (
<Refine
resources={[
{
name: "posts",
show: PostShow,
list: () => (
<div>
<p>This page is empty.</p>
<ShowButton recordItemId="123">Show Item 123</ShowButton>
</div>
),
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);
Properties
recordItemId
recordItemId allows us to manage which data is going to be refreshed. By default, it will read the record id from the route parameters.
setInitialRoutes(["/"]);
import { Refine } from "@refinedev/core";
// visible-block-start
import { RefreshButton } from "@refinedev/mantine";
const MyRefreshComponent = () => {
return <RefreshButton recordItemId="1" />;
};
// visible-block-end
const App = () => {
return (
<Refine
resources={[
{
name: "posts",
list: MyRefreshComponent,
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);
Clicking the button will trigger the useInvalidate hook and then fetch the record whose resource is "post" and whose id is "1".
resource
resource allows us to manage which resource is going to be refreshed. By default, it will read the resource from the current route.
setInitialRoutes(["/"]);
import { Refine } from "@refinedev/core";
// visible-block-start
import { RefreshButton } from "@refinedev/mantine";
const MyRefreshComponent = () => {
return (
<RefreshButton // highlight-next-line
resource="categories"
recordItemId="2"
/>
);
};
// visible-block-end
const App = () => {
return (
<Refine
resources={[
{
name: "posts",
list: MyRefreshComponent,
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);
Clicking the button will trigger the useInvalidate hook and then fetches the record whose resource is "categories" and whose id is "2".
If you have multiple resources with the same name, you can pass the identifier instead of the name of the resource. It will only be used as the main matching key for the resource, data provider methods will still work with the name of the resource defined in the <Refine/> component.
For more information, refer to the
identifiersection of the<Refine/>component documentation →
hideText
hideText is used to show and not show the text of the button. When true, only the button icon is visible.
setInitialRoutes(["/"]);
import { Refine } from "@refinedev/core";
// visible-block-start
import { RefreshButton } from "@refinedev/mantine";
const MyRefreshComponent = () => {
return <RefreshButton hideText recordItemId="123" />;
};
// visible-block-end
const App = () => {
return (
<Refine
resources={[
{
name: "posts",
list: MyRefreshComponent,
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);
resourceNameOrRouteName deprecated
Use resource prop instead.