A customizable toast notification system for React using portals.
npm install react-high-toast
# or
yarn add react-high-toast- Wrap your application with the ToastProvider:
import { ToastProvider, ToastContainer } from 'react-high-toast';
import 'react-high-toast/dist/styles/toast.css'; // Import styles
function App() {
return (
<ToastProvider>
<YourApp />
<ToastContainer />
</ToastProvider>
);
}- Use the toast in any component:
import { useToast } from 'react-high-toast';
function MyComponent() {
const toast = useToast();
const showToast = () => {
toast.success('Operation completed!', {
duration: 3000,
position: 'top-right'
});
};
return <button onClick={showToast}>Show Toast</button>;
}The context provider that manages toast state.
Renders the toasts using React Portal. Place this once in your app.
Hook that returns toast functions:
toast(message, options)toast.success(message, options)toast.error(message, options)toast.warning(message, options)toast.info(message, options)toast.dismiss(id)
| Property | Type | Default | Description |
|---|---|---|---|
| id | string | auto-generated | Custom toast ID |
| type | 'success'|'error'|'warning'|'info'|'default' | 'default' | Toast type |
| duration | number | 5000 (ms) | How long toast stays visible (0 = persistent) |
| position | ToastPosition | 'top-right' | Where toast appears |
| render | function | undefined | Custom render function |
Import the CSS file and override the styles as needed.