documentation/docs/ui-integrations/material-ui/components/buttons/refresh-button/index.md
<RefreshButton> uses Material UI <Button> component to update the data shown on the page via the useInvalidate hook.
:::simple Good to know
You can swizzle this component with the Refine CLI to customize it.
:::
setInitialRoutes(["/posts/show/123"]);
// visible-block-start
import { useShow } from "@refinedev/core";
// highlight-next-line
import { Show, RefreshButton } from "@refinedev/mui";
import { Typography, Stack } from "@mui/material";
const PostShow: React.FC = () => {
const { result: post, query } = useShow<IPost>();
const { data, isLoading } = query;
return (
<Show
isLoading={isLoading}
headerButtons={
// highlight-start
<RefreshButton />
// highlight-end
}
>
<Typography fontWeight="bold">Id</Typography>
<Typography>{post?.id}</Typography>
<Typography fontWeight="bold">Title</Typography>
<Typography>{post?.title}</Typography>
</Show>
);
};
interface IPost {
id: number;
title: string;
}
// visible-block-end
render(
<ReactRouter.BrowserRouter>
<RefineMuiDemo
resources={[
{
name: "posts",
list: "/posts",
show: "/posts/show/:id",
},
]}
>
<ReactRouter.Routes>
<ReactRouter.Route
path="/posts"
element={
<div style={{ padding: 16 }}>
<ReactRouter.Outlet />
</div>
}
>
<ReactRouter.Route index element={<div>List page here...</div>} />
<ReactRouter.Route path="show/:id" element={<PostShow />} />
</ReactRouter.Route>
</ReactRouter.Routes>
</RefineMuiDemo>
</ReactRouter.BrowserRouter>,
);
recordItemId allows us to manage which data is going to be refreshed. By default, the recordItemId is inferred from the route params.
setInitialRoutes(["/posts"]);
// visible-block-start
import { RefreshButton } from "@refinedev/mui";
const MyRefreshComponent = () => {
return (
<RefreshButton
resource="posts"
// highlight-next-line
recordItemId="123"
/>
);
};
// visible-block-end
render(
<ReactRouter.BrowserRouter>
<RefineMuiDemo
resources={[
{
name: "posts",
list: "/posts",
},
]}
>
<ReactRouter.Routes>
<ReactRouter.Route
path="/posts"
element={
<div style={{ padding: 16 }}>
<ReactRouter.Outlet />
</div>
}
>
<ReactRouter.Route index element={<MyRefreshComponent />} />
</ReactRouter.Route>
</ReactRouter.Routes>
</RefineMuiDemo>
</ReactRouter.BrowserRouter>,
);
Clicking the button will trigger the useInvalidate hook and then fetch the record whose resource is "post" and whose id is "123".
resource allows us to manage which resource is going to be refreshed. By default, the resource is inferred from the route params.
setInitialRoutes(["/categories"]);
// visible-block-start
import { RefreshButton } from "@refinedev/mui";
const MyRefreshComponent = () => {
return (
<RefreshButton
// highlight-next-line
resource="categories"
// highlight-next-line
recordItemId="123"
/>
);
};
// visible-block-end
render(
<ReactRouter.BrowserRouter>
<RefineMuiDemo
resources={[
{
name: "posts",
list: "/posts",
},
{
name: "categories",
list: "/categories",
},
]}
>
<ReactRouter.Routes>
<ReactRouter.Route
path="/categories"
element={
<div style={{ padding: 16 }}>
<MyRefreshComponent />
</div>
}
/>
</ReactRouter.Routes>
</RefineMuiDemo>
</ReactRouter.BrowserRouter>,
);
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 is used to show and hide the text of the button. When true, only the button icon is visible.
setInitialRoutes(["/posts"]);
// visible-block-start
import { RefreshButton } from "@refinedev/mui";
const MyRefreshComponent = () => {
return (
<RefreshButton
resource="posts"
recordItemId="123"
// highlight-next-line
hideText
/>
);
};
// visible-block-end
render(
<ReactRouter.BrowserRouter>
<RefineMuiDemo
resources={[
{
name: "posts",
list: "/posts",
},
]}
>
<ReactRouter.Routes>
<ReactRouter.Route
path="/posts"
element={
<div style={{ padding: 16 }}>
<ReactRouter.Outlet />
</div>
}
>
<ReactRouter.Route index element={<MyRefreshComponent />} />
</ReactRouter.Route>
</ReactRouter.Routes>
</RefineMuiDemo>
</ReactRouter.BrowserRouter>,
);
:::simple External Props
It also accepts all props of Material UI Button.
:::