title: useState not working outside of input field (function based Reactjs)
body: <p>I'm using Stateful variables for a signup component on my website. I am sending username and password to my server, then returning a user id number. If I get an error, I am trying to set the errorMsg stateful variable to equal the error message returned. useState works for changing the value in the input field, but it isn't working for the other parts of my app. It doesn't work for Stateful variables passed as props as well. Here is my code.  </p>
  
  <pre><code>import React from 'react';
  import {useState} from 'react';
  import { Link, Redirect } from 'react-router-dom';
  import bcrypt from 'bcryptjs';
  import axios from 'axios';
  
  
  export default function Signup(props) {
  
      const [username, setUsername] = useState('');
      const [password, setPassword] = useState('');
      const [password2, setPassword2] = useState('');
      const [openModal, setOpenModal] = useState(false);
      const [errorMsg, setErrorMsg] = useState('');
      let isAvailable = '';
      let id = null;
      let test = [];
      let axiosError = '';
  
      async function submitAccount() {
          const salt = bcrypt.genSaltSync(10);
          const hash = bcrypt.hashSync(password, salt)
          if (bcrypt.compareSync(password2, hash)) {
  
              await axios.post('http://localhost:5000/players/signup', {
              username: username,
              password: password})
              .then(res =&gt; {id = res.data; console.log(id)})
              .catch (err =&gt; {axiosError = err; console.log(axiosError)})
  
              if (axiosError != '') {
                  axiosError = ''
                  setErrorMsg('This username is taken. Try another')
                  setUsername('')
                  setPassword('')
                  setPassword2('')
                  setOpenModal(true)
                  console.log(errorMsg)
                  console.log(openModal)
              }
  
              else {
                  console.log(id)  
              }
          }
      }    
  
      const handleClose = () =&gt; {
          setOpenModal(false);
      };
  
      return (
          &lt;div&gt;
              &lt;form&gt;
              &lt;input type="text" label='username'
                  onChange={e =&gt; setUsername(e.target.value)}
              /&gt;
              &lt;input type="text" 
                  onChange={e =&gt; setPassword(e.target.value)}
              /&gt;
              &lt;input type="text"
                  onChange={e =&gt; setPassword2(e.target.value)}/&gt;
              &lt;/form&gt;
              &lt;button onClick={submitAccount}&gt;Confirm&lt;/button&gt;
              &lt;p&gt;The results are{props.cookies}&lt;/p&gt;
          &lt;/div&gt;
  
      )
  
  }
  </code></pre>
  
  <p>Here is my code sandbox as well: <a href="https://codesandbox.io/s/epic-lalande-v1nl3?file=/src/App.js" rel="nofollow noreferrer">https://codesandbox.io/s/epic-lalande-v1nl3?file=/src/App.js</a> .Thanks for the help!</p>