Skip to content

toanjo/useAlert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

useAlert - in development

WIP - Custom React Hook for showing Bootstrap Alerts

Usage example:

import { useAlert } from './useAlert'; 

...

const classes = "mx-2 p-4" // String of custom classes to add to the alert element, optional parameter
const [alertState, alertApi] = useAlert("alertsElement", classes); // Access the alert state (type, message, visibility) and API

...

<div id="alertsElement">
</div>

API

  • show(type, message, action) action is an optional parameter intended for adding links to the end of the alert message.
  • hide()
  const action = {
    text: 'with a link',
    url: 'https://google.com'
  }

  <button className="btn" onClick={() => alertApi.show('success','This is a success Message', action)}>Show success</button>
  <button className="btn" onClick={() => alertApi.show('warning','This is a warning Message')}>Show warning</button>
  <button className="btn" onClick={() => alertApi.show('danger','This is a danger Message')}>Show danger</button>
  <button className="btn" onClick={() => alertApi.hide()}>Hide</button>

About

WIP Custom React Hook for showing Bootstrap Alerts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published