The Toaster component provides a container for managing and displaying toast notifications. It's designed to be placed at the root of your application to handle all toast notifications throughout the app.
import { Toaster } from '@dashflowx/core'export default function ToasterExample() {return (<Toaster />)}
Preview:
The main toaster container component.
import { Toaster } from '@dashflowx/core'export default function BasicToaster() {return (<Toaster />)}
Preview:
import { Toaster } from '@dashflowx/core'export default function CustomStyledToaster() {return (<Toaster className="border border-blue-500 rounded-lg p-4" />)}
Preview:
import { Toaster } from '@dashflowx/core'export default function ToasterWithCustomPosition() {return (<Toaster className="top-8 right-8" />)}
Preview:
import { Toaster } from '@dashflowx/core'export default function ToasterWithCustomTheme() {return (<Toaster className="bg-gray-900 text-white" />)}
Preview:
// In your main App componentconst App = () => {return (<div>{/* Your app content */}<Toaster /></div>);};
// In your layout componentconst Layout = ({ children }) => {return (<div>{children}<Toaster /></div>);};
// In a specific page componentconst Page = () => {return (<div>{/* Page content */}<Toaster /></div>);};
// In a modal componentconst Modal = () => {return (<div className="modal">{/* Modal content */}<Toaster /></div>);};
Use only one toaster instance per application.
// ✅ Good - Single instanceconst App = () => (<div><MainContent /><Toaster /></div>);// ❌ Avoid - Multiple instancesconst App = () => (<div><MainContent /><Toaster /><Toaster /></div>);
Position the toaster appropriately for your layout.
// ✅ Good - Appropriate positioning<Toaster className="top-4 right-4" />// ❌ Avoid - Poor positioning<Toaster className="bottom-0 left-0" />
Maintain consistent styling across your application.
// ✅ Good - Consistent styling<Toaster className="standard-toaster-style" />// ❌ Avoid - Inconsistent styling<Toaster className="random-styles" />
Ensure toaster notifications are accessible to all users.
// ✅ Good - Accessible<Toaster />// ❌ Avoid - Not accessible<div>Toast notifications</div>
Use appropriate z-index for toaster visibility.
// ✅ Good - Proper z-index<Toaster className="z-50" />// ❌ Avoid - Poor z-index<Toaster className="z-0" />
You can customize the toaster appearance using CSS classes:
<Toaster className="border border-gray-300 rounded-lg p-4" />
Use different themes for different contexts:
// Light theme<Toaster className="bg-white border-gray-200" />// Dark theme<Toaster className="bg-gray-900 border-gray-700 text-white" />// Brand theme<Toaster className="bg-blue-50 border-blue-200" />
Use different positions for different layouts:
// Top right<Toaster className="top-4 right-4" />// Top left<Toaster className="top-4 left-4" />// Bottom right<Toaster className="bottom-4 right-4" />// Bottom left<Toaster className="bottom-4 left-4" />
Configure toaster dynamically:
const [toasterConfig, setToasterConfig] = useState({});useEffect(() => {// Load toaster configuration from settingsloadToasterConfig().then(setToasterConfig);}, []);
Show toaster based on conditions:
const { user } = useAuth();return (<div><MainContent />{user && <Toaster />}</div>);
Apply custom settings to toaster:
<ToasterclassName="custom-toaster"position="top-right"duration={5000}maxToasts={3}/>
- Toast: For individual toast notifications
- Alert: For alert messages
- Notification: For notifications
- Button: For toast triggers
- Icon: For toast icons
For the complete API reference and advanced usage patterns, see the Toaster API documentation.
