Skip to main content

useAlert

The useAlert hook returns the AlertComponent component to render the Alert and openAlert function to open the AlertComponent programatically.

Importing the hook


import { useAlert } from 'repopup';

Usage


import React from 'react';
import { useAlert , RepopupProvider } from 'repopup';
import ReactDOM from 'react-dom';

const App = () => {
const { AlertComponent: Alert, openAlert } = useAlert({
title: 'Oops',
variant: 'error',
subtitle: 'Sonething wen wrong , please try again !!!',
onConfirm: 'close'
});
return (
<React.Fragment>
<Button onClick={() => openAlert()}>Open</Button>
<Alert />
</React.Fragment>
);
};

ReactDOM.render(
<RepopupProvider>
<App />
</RepopupProvider>,
,document.querySelector('#app'));


Function Signature


function useAlert(
options: UseAlertArgs,
): {AlertComponent:JSX.Element,openAlert: () => void}

Options

OptionTypeDescriptionDefault
closeOnBackdropClickbooleanWheather or not to close the popup on clicking the backdroptrue
confirmButtonTextstringUse this to change the text on the "Confirm"-button.'Confirm'
denyButtonTextstringUse this to change the text on the "Deny"-button.'Deny'
variantsuccess| error| info| warning| question| nullvarinat of a icon to be shownnull
onConfirmReact.MouseEventHandler<HTMLButtonElement> | undefined | 'close'Use this as a click handler for the "Confirm"-button() => {}
onDenyReact.MouseEventHandler<HTMLButtonElement> | undefined| 'close'Use this as a click handler for the "Deny"-button.() => {}
placement'top'| 'center' | 'bottom'| 'center-start'| 'bottom-start'| 'top-start'| 'top-end'| 'bottom-end'| 'center-end'Use this to change Popup window positioncenter
showConfirmButtonbooleanIf set to true, a "Confirm"-button will be shown.false
showDenyButtonbooleanIf set to true, a "Deny"-button will be shown.false
subtitlestringUsed for a description for the popup.
titlestringUsed for the title of the popup