ToastContainer
The rendering target for the library's global toast notification queue. Mount it once near the root of your application. Toasts are dispatched from anywhere using the useToast hook.
Previewβ
Live previewβ Open in Storybook
Importβ
import { ToastContainer } from "@xocialive/ui-components";
import { useToast } from "@xocialive/ui-components/hooks";
Setupβ
Mount ToastContainer inside AppProvider (or inside the Redux Provider if composing manually):
App.tsx
import { ToastContainer } from "@xocialive/ui-components";
function App() {
return (
<>
<Router>
<Routes />
</Router>
<ToastContainer />
</>
);
}
Dispatching toastsβ
import { useToast } from "@xocialive/ui-components/hooks";
function SaveButton() {
const toast = useToast();
const handleSave = async () => {
try {
await saveData();
toast.success("Saved successfully");
} catch {
toast.error("Failed to save");
}
};
return <Button onClick={handleSave}>Save</Button>;
}
Propsβ
| Prop | Type | Default | Description |
|---|---|---|---|
position | "top-right" | "top-left" | "bottom-right" | "bottom-left" | "top-center" | "bottom-center" | "top-right" | Where toasts appear on screen |
maxVisible | number | 3 | Maximum toasts shown simultaneously |
autoHideDuration | number | 4000 | Auto-dismiss delay in milliseconds |
See alsoβ
useToastβ hook for dispatching toasts