Skip to content

Commit

Permalink
⚡️ Reduce refetching APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
0x46616c6b committed Oct 8, 2022
1 parent 86a52bb commit 550fa63
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import '../leaflet.config.js'
import { FeatureProvider } from './components/useFeature'

const App: FC = () => {
const queryClient = new QueryClient()
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 60 * 1000 } },
})

return (
<QueryClientProvider client={queryClient}>
Expand Down
6 changes: 2 additions & 4 deletions src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ interface Props {
const MessageList: FC<Props> = ({ ticker }) => {
const { token } = useAuth()
const { getMessages } = useMessageApi(token)
const { isLoading, error, data } = useQuery(
['messages', ticker.id],
() => getMessages(ticker.id),
{ refetchInterval: false }
const { isLoading, error, data } = useQuery(['messages', ticker.id], () =>
getMessages(ticker.id)
)

if (isLoading) {
Expand Down
5 changes: 1 addition & 4 deletions src/components/settings/InactiveSettingsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ const InactiveSettingsCard: FC = () => {
const { getInactiveSettings } = useSettingsApi(token)
const { isLoading, error, data } = useQuery(
['inactive_settings'],
getInactiveSettings,
{
refetchInterval: false,
}
getInactiveSettings
)

if (isLoading) {
Expand Down
5 changes: 1 addition & 4 deletions src/components/settings/RefreshIntervalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const RefreshIntervalCard: FC = () => {
const { getRefreshInterval } = useSettingsApi(token)
const { isLoading, error, data } = useQuery(
['refresh_interval_setting'],
getRefreshInterval,
{
refetchInterval: false,
}
getRefreshInterval
)

if (isLoading) {
Expand Down
3 changes: 0 additions & 3 deletions src/components/ticker/TickerUserCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const TickerUsersCard: FC<Props> = props => {
['tickerUsers', props.ticker.id],
() => {
return getTickerUsers(props.ticker)
},
{
refetchInterval: false,
}
)

Expand Down
4 changes: 1 addition & 3 deletions src/components/user/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import ErrorView from '../../views/ErrorView'
const UserList: FC = () => {
const { token } = useAuth()
const { getUsers } = useUserApi(token)
const { isLoading, error, data } = useQuery(['users'], getUsers, {
refetchInterval: false,
})
const { isLoading, error, data } = useQuery(['users'], getUsers)

if (isLoading) {
return (
Expand Down
4 changes: 1 addition & 3 deletions src/views/HomeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import { Navigate } from 'react-router'
const HomeView: FC = () => {
const { token, user } = useAuth()
const { getTickers } = useTickerApi(token)
const { isLoading, error, data } = useQuery(['tickers'], getTickers, {
refetchInterval: false,
})
const { isLoading, error, data } = useQuery(['tickers'], getTickers)

if (isLoading) {
return (
Expand Down
6 changes: 2 additions & 4 deletions src/views/TickerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const TickerView: FC = () => {
const { tickerId } = useParams<keyof TickerViewParams>() as TickerViewParams
const tickerIdNum = parseInt(tickerId)

const { isLoading, error, data } = useQuery(
['ticker', tickerIdNum],
() => getTicker(tickerIdNum),
{ refetchInterval: false }
const { isLoading, error, data } = useQuery(['ticker', tickerIdNum], () =>
getTicker(tickerIdNum)
)

if (isLoading) {
Expand Down

0 comments on commit 550fa63

Please sign in to comment.