documentation/versioned_docs/version-3.xx.xx/api-reference/chakra-ui/components/buttons/refresh.md
const { default: routerProvider } = RefineReactRouterV6;
const { default: simpleRest } = RefineSimpleRest;
setRefineProps({
routerProvider,
dataProvider: simpleRest("https://api.fake-rest.refine.dev"),
Layout: RefineChakra.Layout,
Sider: () => null,
catchAll: <RefineChakra.ErrorComponent />,
});
const Wrapper = ({ children }) => {
return (
<RefineChakra.ChakraProvider theme={RefineChakra.refineTheme}>
{children}
</RefineChakra.ChakraProvider>
);
};
<RefreshButton> uses Chakra UI's <Button> component to update the data shown on the page via the useOne method provided by your dataProvider.
:::info-tip Swizzle You can swizzle this component to customize it with the refine CLI :::
setInitialRoutes(["/posts/show/123"]);
import { Refine } from "@pankod/refine-core";
import { ShowButton } from "@pankod/refine-chakra-ui";
// visible-block-start
import { useShow } from "@pankod/refine-core";
import {
Show,
Heading,
Text,
Spacer,
MarkdownField,
//highlight-next-line
RefreshButton,
} from "@pankod/refine-chakra-ui";
const PostShow: React.FC<IResourceComponentsProps> = () => {
const { queryResult } = useShow<IPost>();
const { data, isLoading } = queryResult;
const record = data?.data;
return (
// highlight-next-line
<Show headerButtons={<RefreshButton />} isLoading={isLoading}>
<Heading as="h5" size="sm">
Id
</Heading>
<Text mt={2}>{record?.id}</Text>
<Heading as="h5" size="sm" mt={4}>
Title
</Heading>
<Text mt={2}>{record?.title}</Text>
<Heading as="h5" size="sm" mt={4}>
Content
</Heading>
<Spacer mt={2} />
<MarkdownField value={record?.content} />
</Show>
);
};
// visible-block-end
const App = () => {
return (
<Refine
notificationProvider={RefineChakra.notificationProvider()}
resources={[
{
name: "posts",
show: PostShow,
list: () => (
<RefineChakra.VStack alignItems="flex-start">
<RefineChakra.Text>This page is empty.</RefineChakra.Text>
<ShowButton colorScheme="black" recordItemId="123">
Show Item 123
</ShowButton>
</RefineChakra.VStack>
),
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);
recordItemIdrecordItemId allows us to manage which data is going to be refreshed.
setInitialRoutes(["/"]);
import { Refine } from "@pankod/refine-core";
// visible-block-start
import { RefreshButton } from "@pankod/refine-chakra-ui";
const MyRefreshComponent = () => {
return <RefreshButton colorScheme="black" recordItemId="123" />;
};
// visible-block-end
const App = () => {
return (
<Refine
resources={[
{
name: "posts",
list: MyRefreshComponent,
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);
Clicking the button will trigger the useOne method and then fetches the record whose resource is "post" and whose id is "123".
:::note
<RefreshButton> component reads the id information from the route by default.
:::
resourceNameOrRouteNameresourceNameOrRouteName allows us to manage which resource is going to be refreshed.
setInitialRoutes(["/"]);
import { Refine } from "@pankod/refine-core";
// visible-block-start
import { RefreshButton } from "@pankod/refine-chakra-ui";
const MyRefreshComponent = () => {
return (
<RefreshButton
colorScheme="black"
resourceNameOrRouteName="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 useOne method and then fetches the record whose resource is "categories" and whose id is "2".
:::note
<RefreshButton> component reads the resource name from the route by default.
:::
hideTextIt is used to show and not show the text of the button. When true, only the button icon is visible.
setInitialRoutes(["/"]);
import { Refine } from "@pankod/refine-core";
// visible-block-start
import { RefreshButton } from "@pankod/refine-chakra-ui";
const MyRefreshComponent = () => {
return <RefreshButton colorScheme="black" hideText recordItemId="123" />;
};
// visible-block-end
const App = () => {
return (
<Refine
resources={[
{
name: "posts",
list: MyRefreshComponent,
},
]}
/>
);
};
render(
<Wrapper>
<App />
</Wrapper>,
);