Stop requesting when changing the route in ReactJs

I make an request in react js and i get data using useSelector. So in useEffect i show the message from backend after the request.

useEffect(() => {
  if (selector.response ? .message) {
    message.success(selector.response?.message, 2);
}, [selector.response]);

The code works fine, but appears an issue when i change the page(route). Clicking on another menu item i go to another page and when i come back, the useEffect is triggered again and user again sees the message from message.success(selector.response?.message, 2);.
Question: How to stop showing the message each time after i come back to my route and to show the message just one time?

90 thoughts on “Stop requesting when changing the route in ReactJs”

  1. Howdy! This is kind of off topic but I need some guidance from an established blog.
    Is it tough to set up your own blog? I’m not very techincal but I can figure
    things out pretty fast. I’m thinking about creating my own but I’m not sure where to begin.
    Do you have any ideas or suggestions? Cheers


Leave a Comment