javascript - Root element ID differed from reactRootID -


have react.js component makes 3 ajax calls inside of componentdidmount method , sets state based on result of each call. error in title appeared when "chained" calls execute in specific order. if execute without chaining there no error doesn't work 100% because there no guarantee complete before b , b complete before c.

why react complaining root element id?

componentdidmount() {     var self = this;      // doesn't produce error not acceptable     $.ajax({.. ..}).done(function(result) { self.setstate({a: result}); });     $.ajax({.. b ..}).done(function(result) { self.setstate({b: result}); });     $.ajax({.. c ..}).done(function(result) { self.setstate({c: result}); });      // chaining doesn't work     //self.geta();     // root element id differed reactrootid }  geta() {     var self = this;     $.ajax({...})         .done(function(result) { self.setstate({a: result}); self.getb(); }); }  getb() {     var self = this;     $.ajax({...})         .done(function(result) { self.setstate({b: result}); self.getc(); }); }  getc() {     var self = this;     $.ajax({...})         .done(function(result) { self.setstate({c: result}); }); } 

probably because react doesn't chaining multiple setstate()`s inside componentdidmount.

better setup:

  • call geta componentdidmount.
  • include gotto: 'a' in state
  • in componentdidupdate: call getb (if this.state.gotto == 'a') else call getc

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -