score:0

me helped values.text = '';

onsubmit = {async (values, { setsubmitting, resetform }) => {
      try {
        if (values.target == 'add') {
          await fetch('http://localhost:3000/notes', {
            headers: {
              'content-type': 'application/json',
            },
            method: 'post',
            body: json.stringify({"text":values.text}),
          });
          values.text = '';
        }
      }
      finally {
        setsubmitting(false);
      }

score:1

check that the following function call is not throwing an exception:

request('post', {"text":values.text});

if an exception is being thrown from request(..), then the subsequent call to resetform(..) and setsubmitting(..) will be skipped which would be the reason for the problem you're experiencing.

also, some improvements you might consider would be to make the following changes to your onsubmit handler:

/* define onsubmit callback as async */
onsubmit = { async (values, { setsubmitting, resetform }) => {

    try {

        if(values.target == 'add') {

            /*
            if request is async or returns a promise, wait
            for it before resetting form 
            */
            await request('post', {"text":values.text});

            resetform({"text":""});
        }
    }
    /*
    if you want to handle errors here, do so with a 
    catch block like so:

    catch(err) {
        handleerrorhereifyouchose(err);
    }
    */
    finally {
        /* 
        always ensure form submit state is reset, even if
        unhandled is exception thrown 
        */
        setsubmitting(false);
    }
}}

Related Query

More Query from same tag