Confirmation dialog in React
A small window asking to confirm an action before running it.
Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.
This component also comes in
The code in React
import { useId, type ReactNode } from "react";
import { useDialog } from "./useDialog";
type ConfirmationDialogProps = {
trigger: string;
title: string;
children: ReactNode;
confirmLabel: string;
cancelLabel: string;
onConfirm: () => void;
};
import { useCallback, useEffect, useRef, useState } from "react";
/**
* Drives a native <dialog>: the browser handles the focus trap, Escape and focus return.
* A click on the backdrop (the dialog element itself) closes it too.
*/
export function useDialog() {
const ref = useRef<HTMLDialogElement>(null);
const [open, setOpen] = useState(false);
useEffect(() => {
const dialog = ref.current;Free component: copy it freely, including for commercial projects.
Other modals components in React
Modals components in React
Age verification
FreeA legal-age check window for a wine shop or brewery, accessible, remembered for the session and with the French Evin law notices.
- Tailwind
- React
- CSS
- WordPress

A search covering the page, with popular suggestions, opened from the navigation bar.
- Tailwind
- React
- CSS
- WordPress

A short form in a window to request a call from an advisor.
- Tailwind
- React
- CSS
- WordPress