Skip to content
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

Toast Conflicting or loading infinite in promise at concurrent requests #1101

Open
vikassharmasat opened this issue Apr 25, 2024 · 1 comment

Comments

@vikassharmasat
Copy link

vikassharmasat commented Apr 25, 2024

The toast don't close if API Request function is centralized and in scenario of concurrent requests. It will process only one result others will be in infinite.

there are some screenshots please check

`
import { Bounce, toast } from "react-toastify";

export class ToastUtil {
constructor( unique_key ) {
this.toast_id = {};
this.unique_key = unique_key;
this.toastify_options = {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "colored",
transition: Bounce,
isLoading: false,
};
this.toast = toast;
}

showToast() {
    console.log( this.toast_id, 'this is toast id' )
    this.toast_id[this.unique_key] = this.toast.loading( `Please wait success...` );
}

updateToast( message, type ) {
    this.toast.update( this.toast_id[this.unique_key], {
        render: message,
        type,
        ...this.toastify_options,
    } );
    this.hideToast();
}

hideToast() {
    // this.toast.clearWaitingQueue();
    // this.toast_id = null;
   // delete this.toast_id[this.unique_key];
    console.log( Object.keys( this.toast_id ) );
   setTimeout(() => {
       Object.keys(this.toast_id).forEach(key => toast.dismiss(key));
   },5000);
}

}

api call infinite progress network tab all keys are avaialbe `
@vikassharmasat vikassharmasat changed the title Toast Conflicting in promise at many requests Toast Conflicting or loading infinite in promise at concurrent requests Apr 25, 2024
@kathanshah1206
Copy link

kathanshah1206 commented May 23, 2024

Here is the solution for TypeScript:-
(call the toast first )
image

(define the toast as follows:-)
image
-> the stopPropogation() will prevent default actions

(define the tooglefunction and a timer state as follows:- )
const exitBtnTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const [isToastActive, setIsToastActive] = useState(false);
const [isCloseToastActive, setisCloseToastActive] = useState(false);
image

do same for exit ..thus there is a functionality complete and without any error or bugs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants