field-form
field-form copied to clipboard
make form.submit return a promise
参考以下示例,当form 的 submit 方法返回一个 promise 对象的时候. 用户可以很方便的实现以下需求
-
防止重复提交
-
显示表单正在提交中
const AsyncButton = (props)=>{
const {onClick,children} = props;
const [ing,setIng] = useState(false);
return <a onClick={async()=>{
if(ing) return;
setIng(true);
try{
await onClick();
}finally{
setIng(false);
}
}}>
{children}
</a>
};
const TestComponent = ()=>{
const form = useForm();
return <div>
<Form onFinish={(values)=>{
return axios.post("...",values);
}}>
...
</Form>
<AsyncButton
onClick={()=>{
return form.submit();
}}
>
submit
</AsyncButton>
</div>
};
Codecov Report
Merging #187 into master will increase coverage by
0.00%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #187 +/- ##
=======================================
Coverage 99.89% 99.89%
=======================================
Files 13 13
Lines 912 915 +3
Branches 208 207 -1
=======================================
+ Hits 911 914 +3
Misses 1 1
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/Form.tsx | 100.00% <100.00%> (ø) |
|
| src/useForm.ts | 99.71% <100.00%> (+<0.01%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update e72849a...79b60df. Read the comment docs.
https://github.com/react-component/field-form/pull/108#issuecomment-608241087
急需一个submitting状态。。