Skip to content
Open
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
12 changes: 5 additions & 7 deletions packages/ui/src/hooks/usePayloadAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { useLocale } from '../providers/Locale/index.js'
import { useTranslation } from '../providers/Translation/index.js'
import { requests } from '../utilities/api.js'

type Result = [
type Result<T = any> = [
{
data: any
data: T
isError: boolean
isLoading: boolean
},
Expand All @@ -19,14 +19,12 @@ type Result = [
},
]

type Options = {
initialData?: any
type Options<T = any> = {
initialData?: T
initialParams?: unknown
}

type UsePayloadAPI = (url: string, options?: Options) => Result

export const usePayloadAPI: UsePayloadAPI = (url, options = {}) => {
export const usePayloadAPI = <T = any>(url: string, options: Options<T> = {}): Result<T> => {
const { initialData, initialParams = {} } = options

const { i18n } = useTranslation()
Expand Down