[英]remix form disable submit without useState
使用混音形式
有沒有辦法在不使用 state 的情況下禁用提交按鈕?
例如(這是我知道該怎么做的唯一方法......)
<Form method="post">
<input type="text" onChange={(e) => setValue(e.target.value)} value={value} />
<button type="submit" disabled={value.length < 2}>Submit</button>
</Form>
我喜歡在 remix 中我們可以刪除很多 useState 的東西,這里也可以實現嗎?
由於您正在使用Form
組件
// for some reason they use `useTransition as useNavigation`
// https://remix-forms.seasoned.cc/get-started
import { Form, useTransition as useNavigation } from "@remix-run/react";
const navigation = useNavigation();
const isSubmitting = navigation.state === "submitting";
<button disabled={isSubmitting}>Submit</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.