Last active
September 19, 2021 14:33
-
-
Save iskenxan/671ae9eb1c7d622400229e61c2a87959 to your computer and use it in GitHub Desktop.
useConfirmationDialog hook and implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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