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

onChange callback runs multiple times for a single toast #1159

Open
Mehdi-Hemmatyar opened this issue Sep 24, 2024 · 1 comment
Open

onChange callback runs multiple times for a single toast #1159

Mehdi-Hemmatyar opened this issue Sep 24, 2024 · 1 comment

Comments

@Mehdi-Hemmatyar
Copy link

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
I want to logout user when there is an Auth error
But onChange callback runs multiple times for a single toast

  const handleAuthError = toast.onChange((payload) => {
    console.log(payload);
    if(payload.id === 'oauth-err' && payload.status === 'removed'){
        federatedLogout(pathname)
    }
  });

  useEffect(() => {
    handleAuthError();
  }, []);

this is an test Toast!
check the console
toastAdd

toastRemove

@aaamenezes
Copy link

Hello.

I tested your code and notice that the onchange event is fired when the toast enter and leave the page. So, the value in the console is printed just twice per fire.

For my console is equal of your it, I need to fired the toast a lot of times.

image
image
image

There's a breaking change on the onchange event from the v8 to v9.

I'd test insert the handleAuthError in the use effect's dependencies array

useEffect(() => {
    handleAuthError();
  }, [handleAuthError]);

What's yout React Toastify version?

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