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

fix: add backwards compatibility isStale #64

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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