import * as React from 'react'; import { AlertComponentPropsWithStyle, AlertManager, Provider as AlertProvider, AlertProviderProps, useAlert, withAlert, } from 'react-alert'; class AppWithoutAlert extends React.Component<{ alert: AlertManager }> { render() { return ( ); } } const customContext = React.createContext(undefined); const App = withAlert(customContext)(AppWithoutAlert); const AlertHook = (): JSX.Element => { const alert = useAlert(); return ( ); }; class AlertTemplate extends React.Component { render() { // the style contains only the margin given as offset // options contains all alert given options // message is the alert message... // close is a function that closes the alert const { style, options, message, close } = this.props; return (
{options.type === 'info' && '!'} {options.type === 'success' && ':)'} {options.type === 'error' && ':('} {message}
); } } const options: AlertProviderProps = { position: 'bottom center', timeout: 5000, offset: '30px', transition: 'scale', context: customContext, className: 'cssClass', template: AlertTemplate, containerStyle: { margin: 5, }, }; class Root extends React.Component { render() { return ( ); } }