Back to Refine

useDrawer Hook | Usage & Patterns in Refine v5

documentation/docs/ui-integrations/ant-design/hooks/use-drawer/index.md

3.25.01.5 KB
Original Source

The useDrawer hook helps you manage the Ant Design Drawer component.

ts
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:

tsx
// highlight-start
import { useDrawer } from "@refinedev/antd";
import { Drawer, Button } from "antd";
// highlight-end

export const PostList: React.FC = () => {
  // highlight-next-line
  const { show, drawerProps } = useDrawer();

  return (
    <>
      // highlight-start
      <Button onClick={show}>Show Drawer</Button>
      <Drawer {...drawerProps}>
        <p>Drawer Content</p>
      </Drawer>
      // highlight-end
    </>
  );
};

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

<PropsTable module="@refinedev/antd/useDrawer" />

Return Value

KeyDescriptionType
showReturns the visibility state of the Drawer() => void
closeA function that can open the drawer() => void
drawerPropsSpecify a function that can close the drawer() => void