Warning on Reactjs routes

Asked

Viewed 29 times

0

I have the following custom route configuration

 <BrowserRouter>
            <Switch>
                <IntroducingLayoutRoute exact path="/" component={Main} />
                <IntroducingLayoutRoute path="/about" component={About} />
                <IntroducingLayoutRoute path="/register" component={Register} 

Introducinglayout

const IntroducingLayout = ({ children }) => (                         
    <>
        <Header />
        <Menu />
        
        {children}
        
        <Footer />
    </>
  );  
  
  const IntroducingLayoutRoute = ({component: Component, ...rest}) => {  
    return (  
      <Route {...rest} render={matchProps => (  
        <IntroducingLayout>  
            <Component {...matchProps} />  
        </IntroducingLayout>  
      )} />  
    )  
  };  

Now every time I click on a route I get this warning

In the archive

index.js:1 Warning: Can’t perform a React state update on an unmounted Component. This is a no-op, but it indicates a memory Leak in your application. To fix, Cancel all subscriptions and asynchronous tasks in a useEffect Cleanup Function. in Home (at Introducing/index.js:31)

I tried to use it like this:

const mountedRef = useRef(true)

    const execute = useCallback(() => {
      setLoading(true)
      return asyncFunc()
        .then(res => {
          if (!mountedRef.current) return null
          setData(res)
          return res
        })
    }, [])
  
    useEffect(() => {
      return () => { 
        mountedRef.current = false
      }
    }, [])

But it wasn’t

  • you have protected routes?

  • Yes, I do, but those I want to access are not protected

  • is that it’s weird it’s not done so not on the route! Introducinglayout

  • IntroducingLayout means that these routes will have a specific layout

  • but it is not the component of routes! understood

  • Introlayoutre ta on the route and in the other two code are other names? strange no!

  • you have reference to that code from where?

  • Yes. Here and here

  • IntroLayoutRoute really was my mistake in typing

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.