Examples
Common patterns and examples for using react-toast-msg.
Here are some common usage patterns for react-toast-msg.
Form Submission
Show a success or error toast based on form submission results.
tsx1import { FormSyncForm } from "formsync";2import { toast } from "react-toast-msg";34export default function Example() {5 return (6 <main>7 <FormSyncForm8 formId="YOUR_FORM_ID"9 onSuccess={(res) => toast.success(res.message)}10 onSubmitError={(err) => toast.error(err.message)}11 >12 <input13 type="text"14 name="name"15 placeholder="Name"16 required17 />18 <button type="submit">19 Submit20 </button>21 </FormSyncForm>22 </main>23 );24}
Promise Handling
Instead of managing states manually, you can use toast.promise to handle loading, success, and error outcomes with a single call.
tsx1import { toast } from "react-toast-msg";23const handlePromise = () => {4 const myPromise = new Promise((resolve) => setTimeout(() => resolve("Success!"), 2000));56 toast.promise(myPromise, {7 loading: "Processing...",8 success: (res) => res,9 error: "Error occurred.",10 });11};
Custom Layouts
Since react-toast-msg is lightweight, you can use it alongside other UI components easily.
Check out the Playground for more interactive examples!
How is this guide?
Last updated on March 20, 2026