Version: 5.xx.xx
useDrawer
The useDrawer hook helps you manage the Ant Design Drawer component.
const { show, close, drawerProps } = useDrawer();
You can use the show and close props to control the drawer visibility. You have to descturt drawerProps to the <Drawer/> component.
Usage
Let's see an example:
src/pages/posts/list.tsx
import { useDrawer } from "@refinedev/antd";
import { Drawer, Button } from "antd";
export const PostList: React.FC = () => {
const { show, drawerProps } = useDrawer();
return (
<>
<Button onClick={show}>Show Drawer</Button>
<Drawer {...drawerProps}>
<p>Drawer Content</p>
</Drawer>
</>
);
};
Here, we show a button somewhere on the page and use show on it's onClick callback to trigger opening of the <Drawer>. When the user clicks on the button, the <Drawer> appears.
API Reference
Properties
| Property | Type | Description | Default |
|---|---|---|---|
drawerProps | | Default props for Ant Design {@link https://ant.design/components/drawer/ | |
Return Value
| Key | Description | Type |
|---|---|---|
| show | Returns the visibility state of the Drawer | () => void |
| close | A function that can open the drawer | () => void |
| drawerProps | Specify a function that can close the drawer | () => void |