Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Last active September 19, 2021 14:33
Show Gist options
  • Save iskenxan/671ae9eb1c7d622400229e61c2a87959 to your computer and use it in GitHub Desktop.
Save iskenxan/671ae9eb1c7d622400229e61c2a87959 to your computer and use it in GitHub Desktop.
useConfirmationDialog hook and implementation
import React, { useCallback, useState } from 'react';
import ConfirmationDialog from 'components/global/ConfirmationDialog';
export default function useConfirmationDialog({
headerText,
bodyText,
confirmationButtonText,
onConfirmClick,
}) {
const [isOpen, setIsOpen] = useState(false);
const onOpen = () => {
setIsOpen(true);
};
const Dialog = useCallback(
() => (
<ConfirmationDialog
headerText={headerText}
bodyText={bodyText}
isOpen={isOpen}
onConfirmClick={onConfirmClick}
onCancelClick={() => setIsOpen(false)}
confirmationButtonText={confirmationButtonText}
/>
),
[isOpen]
);
return {
Dialog,
onOpen,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment