tooot/src/utils/queryHooks/account.ts

28 lines
723 B
TypeScript
Raw Normal View History

2021-01-07 19:13:09 +01:00
import client from '@api/client'
import { AxiosError } from 'axios'
import { useQuery, UseQueryOptions } from 'react-query'
export type QueryKey = ['Account', { id: Mastodon.Account['id'] }]
const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
const { id } = queryKey[1]
return client<Mastodon.Account>({
method: 'get',
instance: 'local',
url: `accounts/${id}`
})
}
2021-01-11 21:36:57 +01:00
const useAccountQuery = <TData = Mastodon.Account>({
2021-01-07 19:13:09 +01:00
options,
...queryKeyParams
}: QueryKey[1] & {
options?: UseQueryOptions<Mastodon.Account, AxiosError, TData>
}) => {
const queryKey: QueryKey = ['Account', { ...queryKeyParams }]
return useQuery(queryKey, queryFunction, options)
}
2021-01-11 21:36:57 +01:00
export { useAccountQuery }