Skip to content
This repository was archived by the owner on Jan 2, 2021. It is now read-only.

Commit 16b0ea5

Browse files
authored
feat: v3 support (#81)
* add react-query to devDependencies and bump to latest beta * replaced useQueryCache with useQueryClient and extracted the queryCache from the queryClient I also removed the fallback because with v3, you always need to wrap your app in a QueryClientProvider * updatedAt was renamed to dataUpdatedAt in v3 * queryCache.subscribe passes a query, not a queryCache but we don't really care about the argument because we have the queryCache in the closure * remove the activeQuery directly from the queryCache BREAKING CHANGE: Uses the new React Query v3 API
1 parent 50039d7 commit 16b0ea5

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
},
3232
"peerDependencies": {
3333
"react": "^16.6.3 || ^17.0.0",
34-
"react-query": "^2.0.0"
34+
"react-query": "^3.2.0-beta.23"
3535
},
3636
"devDependencies": {
3737
"@babel/core": "^7.9.0",
@@ -65,6 +65,7 @@
6565
"prettier": "^1.19.1",
6666
"react": "^16.12.0",
6767
"react-dom": "^16.12.0",
68+
"react-query": "^3.2.0-beta.23",
6869
"rollup": "^1.31.1",
6970
"rollup-plugin-babel": "^4.3.2",
7071
"rollup-plugin-commonjs": "^10.1.0",

src/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import match from 'match-sorter'
3-
import { queryCache as cache, useQueryCache } from 'react-query'
3+
import { useQueryClient } from 'react-query'
44
import useLocalStorage from './useLocalStorage'
55
import { useSafeState, isStale } from './utils'
66

@@ -215,7 +215,8 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
215215
function ReactQueryDevtoolsPanel(props, ref) {
216216
const { setIsOpen, ...panelProps } = props
217217

218-
const queryCache = useQueryCache ? useQueryCache() : cache
218+
const queryClient = useQueryClient()
219+
const queryCache = queryClient.getQueryCache()
219220

220221
const [sort, setSort] = useLocalStorage(
221222
'reactQueryDevtoolsSortFn',
@@ -270,7 +271,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
270271
}
271272

272273
const [unsortedQueries, setUnsortedQueries] = useSafeState(
273-
Object.values(queryCache.queries)
274+
Object.values(queryCache.getAll())
274275
)
275276

276277
const [activeQueryHash, setActiveQueryHash] = useLocalStorage(
@@ -306,8 +307,8 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
306307
).length
307308

308309
React.useEffect(() => {
309-
return queryCache.subscribe(queryCache => {
310-
setUnsortedQueries(Object.values(queryCache.queries))
310+
return queryCache.subscribe(() => {
311+
setUnsortedQueries(Object.values(queryCache.getAll()))
311312
})
312313
}, [sort, sortFn, sortDesc, queryCache, setUnsortedQueries])
313314

@@ -564,7 +565,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
564565
>
565566
Last Updated:{' '}
566567
<Code>
567-
{new Date(activeQuery.state.updatedAt).toLocaleTimeString()}
568+
{new Date(activeQuery.state.dataUpdatedAt).toLocaleTimeString()}
568569
</Code>
569570
</div>
570571
</div>
@@ -595,7 +596,7 @@ export const ReactQueryDevtoolsPanel = React.forwardRef(
595596
</Button>{' '}
596597
<Button
597598
onClick={() =>
598-
queryCache.removeQueries(q => q === activeQuery)
599+
queryCache.remove(activeQuery)
599600
}
600601
style={{
601602
background: theme.danger,

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,13 @@
14481448
dependencies:
14491449
regenerator-runtime "^0.13.2"
14501450

1451+
"@babel/runtime@^7.5.5":
1452+
version "7.12.5"
1453+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
1454+
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
1455+
dependencies:
1456+
regenerator-runtime "^0.13.4"
1457+
14511458
"@babel/runtime@^7.8.4":
14521459
version "7.10.3"
14531460
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.10.3.tgz#670d002655a7c366540c67f6fd3342cd09500364"
@@ -6246,6 +6253,13 @@ react-is@^16.8.1, react-is@^16.8.4:
62466253
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.0.tgz#0f37c3613c34fe6b37cd7f763a0d6293ab15c527"
62476254
integrity sha512-GFMtL0vHkiBv9HluwNZTggSn/sCyEt9n02aM0dSAjGGyqyNlAyftYm4phPxdvCigG15JreC5biwxCgTAJZ7yAA==
62486255

6256+
react-query@^3.2.0-beta.23:
6257+
version "3.2.0-beta.23"
6258+
resolved "https://registry.yarnpkg.com/react-query/-/react-query-3.2.0-beta.23.tgz#edba35b12c5ed42a37f287dc2c043729e9e6f3cd"
6259+
integrity sha512-98qwGUgcA/5CsByISNPSzfFmsUofjOE7TNbqqPG9zREjiI+Q0V2Xq3ojdvf01mdLdheNBc7hCJREgM5fBpg+Sg==
6260+
dependencies:
6261+
"@babel/runtime" "^7.5.5"
6262+
62496263
react@^16.12.0:
62506264
version "16.13.0"
62516265
resolved "https://registry.yarnpkg.com/react/-/react-16.13.0.tgz#d046eabcdf64e457bbeed1e792e235e1b9934cf7"

0 commit comments

Comments
 (0)