toast and history.push

UI Components for React
Post Reply
susah80
Posts: 2
Joined: 28 Dec 2020, 15:36

28 Dec 2020, 16:09

I have a scenario like this: after a user is successfully registered, I want to show message with toast and also navigate to another route with history.push().
But history.push seems to mess up with toast?
Is there anything to make it work?

Code: Select all

  const history = useHistory();

  const handleRegister = (values) => {
    authService
      .register(values)
      .then((res) => {
        toast.current.show({
          severity: "success",
          summary: "Successfully Registered",
          detail: "You are auto logged in",
        });
        history.push("/");
      })

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

26 Jan 2021, 17:55

You need a callback after router is changed. I think you can do it like;

Code: Select all

useEffect(() => {
      return history.listen((location) => { 
         toast.current.show({
          severity: "success",
          summary: "Successfully Registered",
          detail: "You are auto logged in",
        });
      }) 
  },[history])
Maybe, this link can help to you;
https://help.mouseflow.com/en/articles/ ... with-react

Best Regards,

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests