react-alert
2kb alerts for React.
Installation
Templates
You can provide your own alert template if you need to. Otherwise you can just plug in one of the following:
Feel free to submit a PR with the link for your own template.
To get started, try installing the basic one:
Peer dependencies
This package expect the following peer dependencies:
"prop-types": "^15.6.2"
"react": "^16.8.1"
"react-dom": "^16.8.1"
"react-transition-group": "^2.5.3"
So make sure that you have those installed too!
Usage
First you have to wrap your app with the Provider giving it the alert template and optionally some options:
Then import the useAlert
hook to be able to show alerts:
And that's it!
You can also use it with a HOC:
Options
You can pass the following options as props to Provider
:
Here's the defaults:
Those options will be applied to all alerts.
Api
After getting the alert
with the useAlert
hook, this is what you can do with it:
Using a custom alert template
If you ever need to have an alert just the way you want, you can provide your own template! Here's a simple example:
Easy, right?
Using a component as a message
You can also pass in a component as a message, like this:
Using multiple Providers
You can use different Contexts to show alerts in different style and position: