tooot/src/utils/queryHooks/emojis.ts

25 lines
558 B
TypeScript
Raw Normal View History

2021-02-20 19:12:44 +01:00
import apiInstance from '@api/instance'
2021-01-07 19:13:09 +01:00
import { AxiosError } from 'axios'
import { useQuery, UseQueryOptions } from 'react-query'
2021-12-18 19:59:38 +01:00
type QueryKeyEmojis = ['Emojis']
2021-01-07 19:13:09 +01:00
2021-12-18 19:59:38 +01:00
const queryFunction = async () => {
const res = await apiInstance<Mastodon.Emoji[]>({
2021-01-07 19:13:09 +01:00
method: 'get',
url: 'custom_emojis'
2021-12-18 19:59:38 +01:00
})
return res.body
2021-01-07 19:13:09 +01:00
}
2021-12-18 19:59:38 +01:00
const useEmojisQuery = ({
2021-01-07 19:13:09 +01:00
options
}: {
2021-12-18 19:59:38 +01:00
options?: UseQueryOptions<Mastodon.Emoji[], AxiosError>
2021-01-07 19:13:09 +01:00
}) => {
2021-12-18 19:59:38 +01:00
const queryKey: QueryKeyEmojis = ['Emojis']
2021-01-07 19:13:09 +01:00
return useQuery(queryKey, queryFunction, options)
}
2021-01-11 21:36:57 +01:00
export { useEmojisQuery }