title: How to return const from react axios function in another file?
body: <p>I have a file with form to call a submit function in another file.
  And I would like to retrieve the response of the request to use it in file 1.
  How can I do that ?</p>
  <p>First file form.js</p>
  <pre><code>handleSubmit(event, user,props) {
  event.preventDefault();
  const nomAppartement = event.target.nomAppartement.value;
  const superficieAppartement = event.target.superficieAppartement.value;
  
  const newAppartementTableau = {
    nom: nomAppartement,
  };
  
  newAppartement(newAppartementTableau);
  const messageRequest = ??;
  </code></pre>
  <p>Second file data.js</p>
  <pre><code>export function newAppartement(newAppartementTableau) {
  
  
  axios({
      method: &quot;post&quot;,
      url: urlAxiosAppartement,
      timeout: 1000 * 5, // Wait for 5 seconds
      headers: {
        &quot;Content-Type&quot;: &quot;application/json&quot;,
        Authorization: &quot;Bearer &quot; + &quot;****&quot;
      },
      data: {
        fields: {
          nom: newAppartementTableau.nom
        }
      }
    })
      .then((response) =&gt; {
        return response;
      })
      .catch((err) =&gt; {
        return err;
      });
  }
  </code></pre>