0

I'm learning in 'The Net Ninja' about routes and navigating between the pages.

In there a component does data fetching and if we navigate(from the Home page) to another page(New Blog), before completing fetch, it gives an error. (Can't perform a state updating over an unmounted component).

enter image description here

So used an Abort Controller and cleanup function to fix it (To stoping fetching after unmounting the component).

But I don't get any error even without using from Abort Controller and cleanup function. So why?

1- please navigate to New Blog

2- Then navigate to Home

3- Then Quickly navigate to New Blog again. (before loading data)

This should give the above error.

Is it for a different versions? In there: RRD: 5.2.0 && react: 17.0.1 and for me: RRD: 5.3.3 && react: 18.1.0

It's project: https://codesandbox.io/s/complete-react-tutorial-forked-c7onv3

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
Arman Ebrahimi
  • 2,035
  • 2
  • 7
  • 20
  • This error doesn't exist in the codesandbox. – Mina Jul 03 '22 at 14:07
  • @Mina Yes and my question is about the same. Why I don't get any error about state updating on unmounted components? (Fetch completes in the background, while we navigated to another page). – Arman Ebrahimi Jul 03 '22 at 14:18
  • 1
    TL;DR This warning was removed in React 18 because it was often a false-positive and lead to anti-pattern code using an `isMounted` check. If you are attempting to cancel in-flight network requests you are on the right path. – Drew Reese Jul 03 '22 at 21:49

0 Answers0