useDialog
Alias of useModal.
Import
TypeScript
import { useDialog } from '@/hooks';API
Signature
useDialog(options?)
When to use
Use useDialog instead of re-implementing the same pattern in multiple components.
SSR / Next.js
DOM extras (scroll lock, focus trap) run only in effects.
Live playground
Edit the example and see it run against the real @/hooks package in this app.
Live playgroundEdit · run with real
@/hooks · useDialogEditor
function D() { const d = useDialog(); return <button onClick={d.open}>{d.isOpen ? 'Open' : 'Closed'}</button>; }
Preview
Implementation source
Full library source for useDialog — copy into your project when you are not installing a package yet.
hooks/ui/useDialog.ts
import { useModal, type UseModalOptions } from './useModal';
/** Alias of {@link useModal}. */
export function useDialog(options?: UseModalOptions) {
return useModal(options);
}
Copy-paste example
useDialog.example.tsx
'use client';
import { useDialog } from '@/hooks';
export function D() {
const d = useDialog();
return <button onClick={d.open}>{d.isOpen ? 'Open' : 'Closed'}</button>;
}Production checklist
- Called only from Client Components or other custom hooks
- Type parameters filled in (e.g.
useFetch<User[]>) - Tip: These are headless — you own the markup and styles.
- Source of truth: open
hooks/ui/useDialog.tsfor implementation details