({
formAction,
formMethod = 'POST',
state = 'non-idle',
}: {
formAction?: string
formMethod?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'
state?: 'submitting' | 'loading' | 'non-idle'
} = {})
| 145 | * want to know if a form is submitting without specific query params. |
| 146 | */ |
| 147 | export function useIsPending({ |
| 148 | formAction, |
| 149 | formMethod = 'POST', |
| 150 | state = 'non-idle', |
| 151 | }: { |
| 152 | formAction?: string |
| 153 | formMethod?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE' |
| 154 | state?: 'submitting' | 'loading' | 'non-idle' |
| 155 | } = {}) { |
| 156 | const contextualFormAction = useFormAction() |
| 157 | const navigation = useNavigation() |
| 158 | const isPendingState = |
| 159 | state === 'non-idle' |
| 160 | ? navigation.state !== 'idle' |
| 161 | : navigation.state === state |
| 162 | return ( |
| 163 | isPendingState && |
| 164 | navigation.formAction === (formAction ?? contextualFormAction) && |
| 165 | navigation.formMethod === formMethod |
| 166 | ) |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * This combines useSpinDelay (from https://npm.im/spin-delay) and useIsPending |
no outgoing calls
no test coverage detected