Back to Refine

Refresh

documentation/versioned_docs/version-3.xx.xx/api-reference/mantine/components/buttons/refresh.md

3.25.05.3 KB
Original Source
tsx
const { default: routerProvider } = RefineReactRouterV6;
const { default: simpleRest } = RefineSimpleRest;
setRefineProps({
  routerProvider,
  dataProvider: simpleRest("https://api.fake-rest.refine.dev"),
  notificationProvider: RefineMantine.useNotificationProvider,
  Layout: RefineMantine.Layout,
  Sider: () => null,
  catchAll: <RefineMantine.ErrorComponent />,
});

const Wrapper = ({ children }) => {
  return (
    <RefineMantine.MantineProvider
      theme={RefineMantine.LightTheme}
      withNormalizeCSS
      withGlobalStyles
    >
      <RefineMantine.Global
        styles={{ body: { WebkitFontSmoothing: "auto" } }}
      />
      <RefineMantine.NotificationsProvider position="top-right">
        {children}
      </RefineMantine.NotificationsProvider>
    </RefineMantine.MantineProvider>
  );
};

<RefreshButton> uses Mantine <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 :::

Usage

tsx
setInitialRoutes(["/posts/show/123"]);
import { Refine } from "@pankod/refine-core";
import { ShowButton } from "@pankod/refine-mantine";

// visible-block-start
import { useShow } from "@pankod/refine-core";
import {
  Show,
  Title,
  Text,
  MarkdownField,
  //highlight-next-line
  RefreshButton,
} from "@pankod/refine-mantine";

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}>
      <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.

tsx
setInitialRoutes(["/"]);
import { Refine } from "@pankod/refine-core";

// visible-block-start
import { RefreshButton } from "@pankod/refine-mantine";

const MyRefreshComponent = () => {
  return <RefreshButton 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. :::

resourceNameOrRouteName

resourceNameOrRouteName allows us to manage which resource is going to be refreshed.

tsx
setInitialRoutes(["/"]);

import { Refine } from "@pankod/refine-core";

// visible-block-start
import { RefreshButton } from "@pankod/refine-mantine";

const MyRefreshComponent = () => {
  return (
    <RefreshButton 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. :::

hideText

It is used to show and not show the text of the button. When true, only the button icon is visible.

tsx
setInitialRoutes(["/"]);

import { Refine } from "@pankod/refine-core";

// visible-block-start
import { RefreshButton } from "@pankod/refine-mantine";

const MyRefreshComponent = () => {
  return <RefreshButton hideText recordItemId="123" />;
};
// visible-block-end

const App = () => {
  return (
    <Refine
      resources={[
        {
          name: "posts",
          list: MyRefreshComponent,
        },
      ]}
    />
  );
};

render(
  <Wrapper>
    <App />
  </Wrapper>,
);

API Reference

Properties

<PropsTable module="@pankod/refine-mantine/RefreshButton" />