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

Commit

Permalink
fix: add backwards compatibility isStale (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
boschni authored Sep 7, 2020
1 parent 40c1593 commit 0854293
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import match from 'match-sorter'
import { queryCache as cache, useQueryCache } from 'react-query'
import useLocalStorage from './useLocalStorage'
import { useSafeState } from './utils'
import { useSafeState, isStale } from './utils'

import {
Panel,
Expand Down Expand Up @@ -196,7 +196,7 @@ export function ReactQueryDevtools({
}

const getStatusRank = q =>
q.state.isFetching ? 0 : !q.observers.length ? 3 : q.isStale() ? 2 : 1
q.state.isFetching ? 0 : !q.observers.length ? 3 : isStale(q) ? 2 : 1

const sortFns = {
'Status > Last Updated': (a, b) =>
Expand Down
10 changes: 8 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import useMediaQuery from './useMediaQuery'

export const isServer = typeof window === 'undefined'

export function isStale(query) {
return typeof query.isStale === 'function'
? query.isStale()
: query.state.isStale
}

export function getQueryStatusColor(query, theme) {
return query.state.isFetching
? theme.active
: query.isStale()
: isStale(query)
? theme.warning
: theme.success
}
Expand All @@ -22,7 +28,7 @@ export function getQueryStatusLabel(query) {
? 'fetching'
: !query.observers.length
? 'inactive'
: query.isStale()
: isStale(query)
? 'stale'
: 'fresh'
}
Expand Down

0 comments on commit 0854293

Please sign in to comment.