Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

javascript - 反应最终形式-无限提交(React final form - infinite submitting)

If we try to send this form several times, we will get infinite submitting .(如果我们尝试多次发送此表格,将会无限提交 。)

If we set the sleep() function on onSubmit , everything works fine.(如果我们在onSubmit上设置sleep()函数,则一切正常。) Why?(为什么?) How to do it right?(怎么做对?) import React from 'react' import { render } from 'react-dom' import { Form, Field } from 'react-final-form' const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)) const onSubmit = async values => { // Everything works fine with sleep() // await sleep(100); console.log('onSubmit...'); } const App = () => ( <Form onSubmit={onSubmit} render={({ handleSubmit, submitting }) => ( <form onSubmit={handleSubmit}> <Field name="notes" component="textarea" placeholder="Notes" /> <button type="submit" disabled={submitting}> Submit </button> </form> )} /> ) render(<App />, document.getElementById('root'))   ask by Adee translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To handle submit synchronously like what are doing, return undefined ie:(为了像处理操作一样同步处理提交,返回undefined即:)

const onSubmit = values => { console.log('onSubmit...'); return; } See https://final-form.org/docs/final-form/types/Config#onsubmit(参见https://final-form.org/docs/final-form/types/Config#onsubmit)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...