This repository has been archived on 2024-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
react-component-form/src/hooks/useFetchState.ts
2023-01-10 21:27:25 +01:00

16 lines
457 B
TypeScript

import { useState } from 'react'
export const fetchState = ['idle', 'loading', 'error', 'success'] as const
export type FetchState = (typeof fetchState)[number]
export const useFetchState = (
initialFetchState: FetchState = 'idle'
): [
fetchState: FetchState,
setFetchState: React.Dispatch<React.SetStateAction<FetchState>>
] => {
const [fetchState, setFetchState] = useState<FetchState>(initialFetchState)
return [fetchState, setFetchState]
}