Skip to content

use-modal-control-query

A hook that opens and closes shadcn/ui dialogs, sheets and drawers from URL query parameters.

shadcn.davidsling.in/hooks/use-modal-control-query

use-modal-control-query website screenshot
Added

About

About use-modal-control-query

use-modal-control-query is a hook for controlling modal components through query parameters. Instead of holding open state in a component, the URL carries it, so a link or a page reload can bring a dialog back. The demo page shows a simple example, a version that keeps extra state in the query, and a set of compatible components.

The hook works with Dialog, Sheet, Drawer, Dropdown Menu, Select and Collapsible. It lives in the davidsling shadcn registry, a growing set of shadcn/ui components and hooks, and installs through the shadcn CLI as source you own. Use it when sharing a deep link to an open modal matters, or when you want several triggers to open the same one.

use-modal-control-query features

5 features

  • Modal open state stored in the query string
  • Works with Dialog, Sheet and Drawer
  • Works with Dropdown Menu, Select and Collapsible
  • Query-stored state example
  • Installs through the shadcn CLI

Install use-modal-control-query

1 command

Terminal

$ pnpm dlx shadcn@latest add https://shadcn.davidsling.in/r/use-modal-control-query.json

What you can build with use-modal-control-query

3 use cases

  • Sharing a link that opens a specific edit dialog
  • Keeping a drawer open across a page reload
  • Opening one dialog from several buttons

1 link

Pricing

Ship it with Pro

The directory is free. Pro adds 6,000+ blocks, 14 premium templates and the MCP server, so your AI editor installs them for you.

4.9/5 out of 5 · 150+ reviewsfrom 150+ founders and developers.

  • Secure checkout via Stripe
  • Code lives in your repo
  • Keep what you've shipped if you cancel
  • License terms

FAQ

Frequently asked questions

What use-modal-control-query is, how to install it, its license and its alternatives.

4.9 out of 5 from 150+ developers

Found your stack? Ship it.

6,000+ blocks, premium templates and MCP in every Pro plan. The directory stays free.

Get Pro