Skip to content

Commit

Permalink
refactor: use @tanstack/react-query instead of react-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 1, 2023
1 parent 1d71ef3 commit abf2b15
Show file tree
Hide file tree
Showing 24 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react'
import { QueryClient, QueryClientProvider } from 'react-query'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ThemeProvider } from 'styled-components'
import Routers from './routes'
import Toast from './components/Toast'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header/BlockchainComp/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useLayoutEffect, FC, memo } from 'react'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { isMainnet } from '../../../utils/chain'
import WhiteDropdownIcon from '../../../assets/white_dropdown.png'
import BlueDropUpIcon from '../../../assets/blue_drop_up.png'
Expand Down
2 changes: 1 addition & 1 deletion src/components/NftCollectionInventory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AxiosResponse } from 'axios'
import { Link } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Base64 } from 'js-base64'
import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils'
import { useTranslation } from 'react-i18next'
Expand Down
2 changes: 1 addition & 1 deletion src/components/NftCollectionOverview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AxiosResponse } from 'axios'
import { Link } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Tooltip } from 'antd'
import { useTranslation } from 'react-i18next'
import { explorerService } from '../../services/ExplorerService'
Expand Down
2 changes: 1 addition & 1 deletion src/components/NftCollectionTransfers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AxiosResponse } from 'axios'
import { FC, useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Tooltip } from 'antd'
import { Base64 } from 'js-base64'
import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils'
Expand Down
7 changes: 3 additions & 4 deletions src/components/QueryResult/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactElement } from 'react'
import { UseQueryResult } from 'react-query'
import { DefinedUseQueryResult } from '@tanstack/react-query'
import { LOADING_WAITING_TIME } from '../../constants/common'
import Error from '../Error'
import Loading from '../Loading'
Expand All @@ -12,7 +12,7 @@ export function QueryResult<TData, TError>({
errorRender,
loadingRender,
}: {
query: UseQueryResult<TData, TError>
query: DefinedUseQueryResult<TData, TError>
children: (data: TData) => ReactElement
delayLoading?: boolean
errorRender?: (err: TError) => ReactElement
Expand All @@ -22,10 +22,9 @@ export function QueryResult<TData, TError>({

switch (query.status) {
case 'error':
return errorRender ? errorRender(query.error) : <Error />
return errorRender && query.error ? errorRender(query.error) : <Error />
case 'success':
return children(query.data)
case 'idle':
case 'loading':
default:
return loadingRender ? (
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/providers/dasQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, FC, useCallback, useContext, useMemo, useRef } from 'react'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { explorerService } from '../../services/ExplorerService'
import { unique } from '../../utils/array'
import { throttle } from '../../utils/function'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Address/AddressComp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios, { AxiosResponse } from 'axios'
import { useState, useEffect, FC } from 'react'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Radio } from 'antd'
import { Base64 } from 'js-base64'
import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Address/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useParams } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import AddressHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/BlockDetail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useParams, useLocation } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import BlockHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/BlockList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Fragment, useMemo, FC } from 'react'
import { Link, useLocation } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { parseSimpleDate } from '../../utils/date'
import { BlockListPanel, ContentTable, HighLightValue, BlockRewardContainer, BlockRewardPanel } from './styled'
import Content from '../../components/Content'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/FeeRateTracker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useRef, useState } from 'react'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import styles from './styles.module.scss'
import Content from '../../components/Content'
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, memo, useMemo, useRef } from 'react'
import { useHistory } from 'react-router'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useResizeDetector } from 'react-resize-detector'
import {
HomeHeaderItemPanel,
Expand Down Expand Up @@ -194,7 +194,7 @@ export default () => {
const tipBlockNumber = useLatestBlockNumber()

const blocksQuery = useQuery(
'latest_blocks',
['latest_blocks'],
async () => {
// Using the size of list pages to request will be more friendly to the data reuse of the list pages.
const { data, meta } = await explorerService.api.fetchLatestBlocks(ListPageParams.PageSize)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NervosDao/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useHistory } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import Content from '../../components/Content'
import { DaoContentPanel, DaoTabBarPanel } from './styled'
import DaoTransactions from './DaoTransactions'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NftCollectionInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AxiosResponse } from 'axios'
import { Link, useParams, useHistory } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Popover } from 'antd'
import { TFunction, useTranslation } from 'react-i18next'
import Content from '../../components/Content'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NftCollections/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AxiosResponse } from 'axios'
import { useHistory, useLocation } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import { NFTCollection, ListOnDesktop, ListOnMobile, isTxFilterType } from './List'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/NftInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AxiosResponse } from 'axios'
import { Link, useParams, useHistory } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Tooltip } from 'antd'
import { Base64 } from 'js-base64'
import { hexToBytes } from '@nervosnetwork/ckb-sdk-utils'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Script/ScriptsComp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react'
import { useHistory } from 'react-router'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { AxiosResponse } from 'axios'
import camelcase from 'camelcase'
import { useParams } from 'react-router-dom'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Script/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
import { useHistory } from 'react-router'
import { useParams } from 'react-router-dom'
import { Tabs } from 'antd'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { AxiosResponse } from 'axios'
import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SimpleUDT/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { Link, useHistory, useLocation, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { Popover } from 'antd'
import SimpleUDTHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Tokens/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Tooltip } from 'antd'
import { Link, useHistory } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import Content from '../../components/Content'
import Pagination from '../../components/Pagination'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Transaction/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useParams } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useTranslation } from 'react-i18next'
import TransactionHashCard from '../../components/Card/HashCard'
import Content from '../../components/Content'
Expand Down
6 changes: 3 additions & 3 deletions src/pages/TransactionList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, ReactNode } from 'react'
import { Link, useLocation } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { parseSimpleDate } from '../../utils/date'
import Content from '../../components/Content'
import { shannonToCkb } from '../../utils/util'
Expand Down Expand Up @@ -236,7 +236,7 @@ const TransactionsPanel: FC<{ type: TxStatus }> = ({ type }) => {
type === 'confirmed' ? s === 'height' || s === 'capacity' : s === 'capacity' || s === 'time' || s === 'fee',
)

const query = useQuery(
const query = useQuery<{ transactions: Array<State.Transaction>; total: number }>(
[`${type}-transactions`, type, currentPage, pageSize, sortBy, orderBy] as const,
async ({ queryKey }) => {
const [, type] = queryKey
Expand All @@ -262,7 +262,7 @@ const TransactionsPanel: FC<{ type: TxStatus }> = ({ type }) => {
initialData:
state?.type === 'TransactionListPage' && state.createTime + stateStaleTime > Date.now()
? state.transactionsDataWithFirstPage
: undefined,
: { total: 0, transactions: [] },
},
)

Expand Down
2 changes: 1 addition & 1 deletion src/utils/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
systemScripts,
} from '@nervosnetwork/ckb-sdk-utils'
import { useHistory, useLocation } from 'react-router-dom'
import { useQuery } from 'react-query'
import { useQuery } from '@tanstack/react-query'
import { useResizeDetector } from 'react-resize-detector'
import { interval, share } from 'rxjs'
import { AppCachedKeys } from '../constants/cache'
Expand Down

0 comments on commit abf2b15

Please sign in to comment.