Warning: Can't perform a React state update on an unmounted component.
See original GitHub issueThis is the code for useMuation
const [tokenAuthCall, { loading: mutationLoading, error: mutationError }] = useMutation(LOGIN_MUTATION, {
refetchQueries: [ { query: ME_QUERY }], awaitRefetchQueries: true,
})
But on using refetchQueries it gives the following warning
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.
This is my nav code:
function NavContents(props) {
let me
let data = MeQuery()
try {
me = data.me
} catch {
me = false
}
return (
<React.Fragment>
{me && (
<li className="nav-item">
<NavLink to="/profile" className="nav-link">
{me.name}
</NavLink>
</li>
)}
{me && (
<li className="nav-item">
<NavLink to="/signout" className="nav-link">
(SignOut)
</NavLink>
</li>
)}
<React.Fragment>
)
And the is MeQuery()
import React, { Component } from "react"
import { gql, useQuery } from "@apollo/client"
const ME_QUERY = gql`
query {
me {
email
name
}
}
`
function MeQuery() {
const { loading, error, data } = useQuery(ME_QUERY)
let value
if (loading) return "Loading..."
if (error) {
value = false
}
value = data
return value
}
export default MeQuery
export {ME_QUERY}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:50
- Comments:50 (5 by maintainers)
Top Results From Across the Web
Can't perform a React state update on an unmounted ...
Here is a simple solution for this. This warning is due to when we do some fetch request while that request ...
Read more >Can't perform a react state update on an unmounted component
To solve the "Warning: Can't perform a React state update on an unmounted component", declare an isMounted boolean in your useEffect hook that...
Read more >React: Prevent state updates on unmounted components
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...
Read more >Can't perform a React state update on an unmounted ... - GitHub
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...
Read more >React prevent state updates on unmounted components
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...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Happened also when route changes while current route has a useQuery
Still actual!!