score:-1

why do you have 'new state: ' in the setstate? the onchange function is called on every key press or change, so you shouldn't add your own text inside of the setstate function. if you wanna use es6, you can change the onchange call to:

(event) => this.handleinputchange(event.target.value)

and the handleinput function to:

handleinputchange(value) {
  this.setstate({
    text: value
  })
}

if you need the 'new state: ' string before the input text then put it inside of a span before the input instead.

score:1

store the changed value, setstate() is asynchronous.

handleinputchange(event) {
  const myvalue = event.target.value;
  this.setstate({
    text: myvalue
  })
}

score:6

because setstate is asynchronous. but fortunately there is a callback parameter in the method call which you can use to get the value like this

    this.setstate({
        text: 'new state: ' + event.target.value
    }, () => {
        console.log(text)
    })

btw you are not assigning anything to setstate it's a method call. besides that since events are synthetic events in react you have to store the current target in a variable to not lose the event for example like this

    const savevalue = event.target.value;
    this.setstate({
        text: 'new state: ' + savevalue 
    });
    console.log(savevalue);

Related Query

More Query from same tag