I've solved this exercise a few times now, but why does my console.log(this.state) return the previous state?(and not the current one)

I just finished working with this exercise, but I’m in the midst of playing around with it, and I came across a question. With the following code, when I console.log(this.state) in my submitMessage() function, it console.logs the previous state? Why is the function operating in that way?

class DisplayMessages extends React.Component {
  constructor(props) {
    this.state = {
      input: '',
      messages: []
  // add handleChange() and submitMessage() methods here
    // this.handleChange = this.handleChange.bind(this)
    // this.submitMessage = this.submitMessage.bind(this)

    handleChange(event) {
          input: event.target.value,
          messages: this.state.messages

    submitMessage() {
        input: '',
        messages: [...this.state.messages, this.state.input]

  render() {
    return (
        <h2>Type in a new Message:</h2>
        { /* render an input, button, and ul here */ }
        <input onChange={this.handleChange.bind(this)} value={this.state.input}/>
        <button onClick={this.submitMessage.bind(this)}>Submit</button>
        {this.state.messages.map((x,i) =>{return <li key ={i}>{x}</li>})}
        { /* change code above this line */ }

Because it executes asynchronously. Console.log in a callback for the updated state to be reflected.

        input: '',
        messages: [...this.state.messages, this.state.input]
        } , () => { console.log(this.state)});

Oh, I had no idea that was asynchronous . Good thing I asked, that was important for me to know. Thanks!

You can read more Here and This stackoverflow Question. Both are interesting reads.