Search code examples
reactjsreduxredux-form

Why do we need to throttle onSubmt validation of redux-form?


According to the documentation of Redux-Form, specifically chapter regarding Submit Validation, we need to simulate server latency in validation function:

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))

function submit(values) {
  return sleep(1000).then(() => {
    // simulate server latency

I can't seem to understand the reason why would we do that. Why can't we just validate without deferring? I tested it in my application and it seems to be working.


Solution

  • This is not something that you need to include in your own code. It is part of the example to make it more true to life, so you can see that it really functions properly.

    You can imagine that without latency, you'll have no opportunity to see how the form behaves until the server responds, for example, how submitting prop comes into play.