Files
picpeak/frontend/src/hooks/useModal.ts
T
Paul Nothaft 0f230f53fb refactor(frontend): useMutationWithToast + useModal hooks, migrate admin surfaces
- 92 mutations across 40 files moved to useMutationWithToast
  (success/error toast + invalidateKeys); complex flows left as-is
- 24 boolean modal flags moved to useModal
- Mutations without an original onError intentionally not migrated
  to avoid introducing new error toasts
2026-07-03 07:49:45 +02:00

21 lines
621 B
TypeScript

import { useCallback, useState } from 'react';
export interface UseModalResult {
isOpen: boolean;
open: () => void;
close: () => void;
toggle: () => void;
}
/**
* Small helper for the ubiquitous `const [showX, setShowX] = useState(false)`
* modal open/close flag.
*/
export function useModal(initialOpen = false): UseModalResult {
const [isOpen, setIsOpen] = useState(initialOpen);
const open = useCallback(() => setIsOpen(true), []);
const close = useCallback(() => setIsOpen(false), []);
const toggle = useCallback(() => setIsOpen((prev) => !prev), []);
return { isOpen, open, close, toggle };
}