title: Why does setState callback throw an error: "State updates from the useState() and useReducer() Hooks don't support the second callback argument..."
body: <p>I am trying to create a setState callback as setState is async and I want to safely use the state afterwards.</p>
  <pre><code>function Register(props) {
      const [errMsg, setErrMsg] = useState(null);
      
      const fullNameInputRef = useRef();
      const emailInputRef = useRef();
      const passwordInputRef = useRef();
  
  
      function submitHandler(event) {
          event.preventDefault(); //prevents full page reload
          
          const enteredFullName = fullNameInputRef.current.value;
          const enteredEmail= emailInputRef.current.value;
          const enteredPassword = passwordInputRef.current.value;
  
          axios({
              method: 'post',
              url: 'http://localhost:3000/api/users/register',
              data: {
                username: enteredFullName,
                email: enteredEmail,
                password: enteredPassword
              }
            }).then( (res) =&gt; {
                if (res.data.success == false) {
                    setErrMsg(`${res.data.message}`, () =&gt; {  /* setState Callback */
                      console.log(errMsg);
                    });
                }
                else { console.log(res)}
            }).catch( (err) =&gt; {
                console.log(err)
                setErrMsg(&quot;An error has occured. Please try again later&quot;)
            });
      
        }
  </code></pre>
  <p>But console.log inside the callback doesn`t work. (<strong>console.log(errMsg);</strong>)
  I am getting the following error:</p>
  <blockquote>
  <p>Warning: State updates from the useState() and useReducer() Hooks don't support the second callback argument. To execute a side effect after rendering, declare it in the component body with useEffect().</p>
  </blockquote>
  <p>What am I missing?</p>