title: React: How to clear form only after SUCCESSFUL submit?
body: <p>I have created a form in React that is cleared after each submission. However, the form is also cleared if the submission is not successful, for example, if a field is filled in incorrectly by the user. This is of course quite annoying, as the user has to repeat the whole process of data entry. So what I'm trying to implement is a clearing that is only activated after a successful submission. If a submission is not successful, the data remains in the form so that the user can rework the data.</p>
  
  <p>To manage the states I use Redux.</p>
  
  <p><strong>Submit Function</strong></p>
  
  <pre><code> onSubmit = e =&gt; {
      e.preventDefault();
      let { title, content, audio} = this.state;
      let formDataStory = new FormData(); // create form formData
      formDataStory.append('audio', audio); // add audio to formData
      formDataStory.append('title', title); // add title to formData
      formDataStory.append('content', content); // add content to formData
      this.props.addStory(formDataStory); // call addStory function with formDataStory as Input to create new Story
      this.setState({
        title: "", // clear title field after submission
        content:"", // clear content field after submission
      });
      this.inputRef.current.value = ''; // clear file field after submission 
    };
  </code></pre>
  
  <p><strong>Add Story Action</strong></p>
  
  <pre><code>export const addStory = formDataStory =&gt; (dispatch, getState) =&gt; {
    axios.post(apiBase +"/story/", formDataStory, tokenConfig(getState) )
      .then(res =&gt; {
        dispatch(createMessage({ addStory: "Story Added" }));
        dispatch({
          type: ADD_STORY,
          payload: res.data
        });
      })
      .catch(err =&gt;
        dispatch(returnErrors(err.response.data, err.response.status))
      );
  };
  
  </code></pre>
  
  <p>At the moment I don't know how to implement this, and I haven't found a good read about it (my assumption is something like this: if the story is successfully added, than -> clear form, else -> keep form). I am happy about every support on that.</p>