8

Here's the code I have:

import { useState } from 'react'
import { QueryClientProvider, QueryClient } from 'react-query'
import { ReactQueryDevtools } from 'react-query-devtools'

import Navbar from './components/Navbar'
import Planets from './components/Planets'
import People from './components/People'

const queryClient = new QueryClient

function App() {

  const [page, setPage] = useState('planets')

  return (
    <QueryClientProvider client={queryClient}>
      <div className="App">
        <h1>Star Wars Info</h1>
        <Navbar setPage={setPage} />

        <div className="content">
          {page === 'planets' ? <Planets /> : <People />}
        </div>
      </div>
      <ReactQueryDevtools initialIsOpen={false} />
    </QueryClientProvider>
  )
}
export default App

... which fails with this error:

TypeError: Cannot read property 'queries' of undefined

enter image description here

What should I do to fix this?

1
  • Sometimes this error exist when you forgot to use "new" key word for QueryClient() Commented Dec 13, 2022 at 7:39

4 Answers 4

28

According to this line...

import { QueryClientProvider, QueryClient } from 'react-query'

... you're using the newer version of React Query library, v3. Introducing QueryClientProvider to replace both ReactQueryConfigProvider and ReactQueryCacheProvider was one of its key features.

However, even more important feature of this library for your code was merging Devtools into the package. To import them, you should now use...

import { ReactQueryDevtools } from 'react-query/devtools'

The older, already archived version of Devtools - which is imported in your code - is compatible with React Query v2, but not with v3.

It's not quite clear from the error message alone what exactly is broken. I suspect it's an attempt to use one of the components removed/modified in React Query v3, such as QueryCache.


As a sidenote: if you follow some tutorial to the letter, yet something is clearly broken, most of the time it's incompatibility of dependencies' versions to blame. React ecosystem evolves fast, and sometimes things are broken just because their parts evolve with different speed.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, man, this worked for me, I was following Tanner Linsley course then this happened to me. I think he needs to update his course!
for me it was merely using import { ReactQueryDevtools } from 'react-query/devtools' instead of npm i react-query-devtools which solved the problem.
4

As the documentation says:

The devtools are bundle split into the react-query/devtools package. No need to install anything extra.

Comments

0

Reason

Using an old version of React Query Dev tools caused the issue.

Solution

npm i @tanstack/react-query-devtools

It can be any Component where the below code can be written but prefer way is to write it in the main app.js or router file. So that dev tools can be accessed on all pages.

import { ReactQueryDevtools } from '@tanstack/react-query-devtools'

function App() {
  return (
      <ReactQueryDevtools initialIsOpen={false} />
  )
}```

Comments

-1

If you are on v3, make sure to use the devtools that come with the library (react-query/devtools), not the separate package react-query-devtools.

1 Comment

What extra information does this offer over the accepted answer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.