Skip to content

Commit 44a44b9

Browse files
feat: await results from submit hooks
1 parent 96a2142 commit 44a44b9

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

app/components/search-bar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Form, useSearchParams, useSubmit } from 'react-router';
21
import { useId } from 'react'
2+
import { Form, useSearchParams, useSubmit } from 'react-router'
33
import { useDebounce, useIsPending } from '#app/utils/misc.tsx'
44
import { Icon } from './ui/icon.tsx'
55
import { Input } from './ui/input.tsx'
@@ -23,8 +23,8 @@ export function SearchBar({
2323
formAction: '/users',
2424
})
2525

26-
const handleFormChange = useDebounce((form: HTMLFormElement) => {
27-
submit(form)
26+
const handleFormChange = useDebounce(async (form: HTMLFormElement) => {
27+
await submit(form)
2828
}, 400)
2929

3030
return (

app/root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ function UserDropdown() {
316316
<DropdownMenuItem
317317
asChild
318318
// this prevents the menu from closing before the form submission is completed
319-
onSelect={(event) => {
319+
onSelect={async (event) => {
320320
event.preventDefault()
321-
submit(formRef.current)
321+
await submit(formRef.current)
322322
}}
323323
>
324324
<Form action="/logout" method="POST" ref={formRef}>

app/routes/admin+/cache.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { invariantResponse } from '@epic-web/invariant'
22
import { type SEOHandle } from '@nasa-gcn/remix-seo'
3-
import { redirect, type LoaderFunctionArgs, type ActionFunctionArgs } from 'react-router';
4-
import { Form, Link, useFetcher, useLoaderData, useSearchParams, useSubmit } from 'react-router';
3+
import {
4+
redirect,
5+
type LoaderFunctionArgs,
6+
type ActionFunctionArgs,
7+
Form,
8+
Link,
9+
useFetcher,
10+
useLoaderData,
11+
useSearchParams,
12+
useSubmit,
13+
} from 'react-router'
514
import { GeneralErrorBoundary } from '#app/components/error-boundary'
615
import { Field } from '#app/components/forms.tsx'
716
import { Spacer } from '#app/components/spacer.tsx'
@@ -86,8 +95,8 @@ export default function CacheAdminRoute() {
8695
const limit = searchParams.get('limit') ?? '100'
8796
const instance = searchParams.get('instance') ?? data.instance
8897

89-
const handleFormChange = useDebounce((form: HTMLFormElement) => {
90-
submit(form)
98+
const handleFormChange = useDebounce(async (form: HTMLFormElement) => {
99+
await submit(form)
91100
}, 400)
92101

93102
return (

0 commit comments

Comments
 (0)