documentation/docs/ui-integrations/ant-design/components/buttons/import-button/index.md
<ImportButton> is compatible with the useImport hook and is meant to be used as it's upload button.
It uses Ant Design's <Button> and <Upload> components. It wraps a <Button> component with an <Upload> component and accepts properties for <Button> and <Upload> components separately.
:::simple Good to know
You can swizzle this component to customize it with the Refine CLI
:::
setInitialRoutes(["/posts"]);
// visible-block-start
import {
List,
useTable,
// highlight-start
useImport,
ImportButton,
// highlight-end
} from "@refinedev/antd";
import { Table } from "antd";
const PostList: React.FC = () => {
const { tableProps } = useTable<IPost>();
// highlight-next-line
const importProps = useImport<IPostFile>();
return (
<List
headerButtons={
// highlight-next-line
<ImportButton {...importProps} />
}
>
<Table {...tableProps} rowKey="id">
<Table.Column dataIndex="id" title="ID" />
<Table.Column dataIndex="title" title="Title" />
</Table>
</List>
);
};
interface IPost {
id: number;
title: string;
}
interface IPostFile {
title: string;
categoryId: number;
}
// visible-block-end
render(
<ReactRouter.BrowserRouter>
<RefineAntdDemo
resources={[
{
name: "posts",
list: "/posts",
},
]}
>
<ReactRouter.Routes>
<ReactRouter.Route
path="/posts"
element={
<div style={{ padding: 16 }}>
<ReactRouter.Outlet />
</div>
}
>
<ReactRouter.Route index element={<PostList />} />
</ReactRouter.Route>
</ReactRouter.Routes>
</RefineAntdDemo>
</ReactRouter.BrowserRouter>,
);
hideText is used to hide the text of the button. When its true, only the button icon will be visible.
setInitialRoutes(["/posts"]);
// visible-block-start
import { ImportButton, useImport } from "@refinedev/antd";
const MyImportComponent = () => {
const importProps = useImport();
return (
<ImportButton
{...importProps}
// highlight-next-line
hideText
/>
);
};
// visible-block-end
render(
<ReactRouter.BrowserRouter>
<RefineAntdDemo
resources={[
{
name: "posts",
list: "/posts",
},
]}
>
<ReactRouter.Routes>
<ReactRouter.Route
path="/posts"
element={
<div style={{ padding: 16 }}>
<ReactRouter.Outlet />
</div>
}
>
<ReactRouter.Route index element={<MyImportComponent />} />
</ReactRouter.Route>
</ReactRouter.Routes>
</RefineAntdDemo>
</ReactRouter.BrowserRouter>,
);