New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can i pass dynamic variable to toast.promise loading? #321
Comments
My solution is to use useRef. This is implement example: import { useRef } from "react";
const MyComponent = (props: any) => {
const textRef = useRef<HTMLSpanElement>(null);
const updateText = (text: string) => {
if (textRef?.current) textRef.current.innerText = text;
};
const onHandle = async () => {
updateText("Initiating...");
await delay(3000);
updateText("Optimizing images...");
await delay(3000);
updateText("Saving...");
};
const onClick = () => {
toast.promise(onHandle(), {
loading: <span ref={textRef}>Saving...</span>,
success: "Successfully!",
error: (error) => {
console.log(error);
return "Something were wrong.";
},
});
};
return (
<div>
<button onClick={onClick}>Show me</button>
</div>
);
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
something like this
The text was updated successfully, but these errors were encountered: