#Display toasts when useFetcher, useSubmit finish
1 messages · Page 1 of 1 (latest)
Use the session flashing pattern: https://github.com/remix-run/examples/tree/main/toast-message.
wow, that's annoying... makes it difficult to pass a react fragment as the message (incase i want to bold certain text) as well as different icons for each toast, since it has to be serialized into a cookie
is this the only way?
i ended up doing using the transition.submission.key or fetcher.submission.key and useEffect to add new toasts:
const transition = useTransition();
useEffect(() => {
if (!addToast) return;
if (transition.state === "loading" && transition.submission) {
addToast((prev) => {
if (prev.find((t) => t.id === transition.submission.key)) return prev;
if (transition.submission.formData.get("_method") === "delete") {
return [
...prev,
{
id: transition.submission.key,
message: (
<>
Deleted <span className="font-medium">{post.title}</span>
</>
),
icon: faTrash,
type: "success",
},
];
}
return prev;
});
}
}, [transition, addToast, post]);
Session flash is not the only way.
Yea, something like this is okay too.
really wish i could just await fetcher.submit/fetcher.load!