MCPcopy
hub / github.com/epicweb-dev/epic-stack / useIsPending

Function useIsPending

app/utils/misc.tsx:147–167  ·  view source on GitHub ↗
({
	formAction,
	formMethod = 'POST',
	state = 'non-idle',
}: {
	formAction?: string
	formMethod?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'
	state?: 'submitting' | 'loading' | 'non-idle'
} = {})

Source from the content-addressed store, hash-verified

145 * want to know if a form is submitting without specific query params.
146 */
147export 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

Callers 15

SearchBarFunction · 0.90
ProviderConnectionFormFunction · 0.90
DeleteNoteFunction · 0.90
NoteEditorFunction · 0.90
PhotoRouteFunction · 0.90
TwoFactorRouteFunction · 0.90
ChangePasswordRouteFunction · 0.90
CreatePasswordRouteFunction · 0.90
ChangeEmailIndexFunction · 0.90
SignupRouteFunction · 0.90
OnboardingProviderRouteFunction · 0.90
ResetPasswordPageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected