javascript - state not updating correctly -


i have simple code valdiations inputs in state:

validateform2: function () {         var formisvalid = true;         (var = 0; < this.state.inputs.length; i++) {             var currentinput = this.state.inputs[i];             var inputvalue = this.state[currentinput.name];             if (!currentinput.validate(inputvalue)) {                 formisvalid = false;                 this.makeinvalid(currentinput.name);             }         }          return formisvalid;     }, 

makeinvalid calls other method showing error message:

 makeinvalid: function (elemname) {    ...    this.showvalidationerror(inputs[i].validatemessage);    ... } 

this showvalidtionmessage:

showvalidationerror: function (message) {         var summary = this.state.validationsummary + message;         this.setstate({             validationsummary: summary         });                 } 

when have 2 errors showvalidationerror called twice , in debugger see there 2 different message come function, validationsummary has 1 message(the second). don't know why. also, tried write console.log(this.state.validationsummary) after setstate , in console empty string after first call. error?

ps. have read documentation , there written setstate() not mutate this.state creates pending state transition. may reason? if how rewrite code?


Comments