Converting from a string to a class object in javascript -


so i'm doing requires me take class (that declared in separate file) in case react component, , convert string, remove things through regex make react component smaller, , convert class , set new object state. if not familiar react in simple terms need go class --> string --> class object

this have far , returns looking same object when try use , set state, loses context or , var namespace comes being undefined.

if try go straight newstate parameter , set state in function "_this.setstate()" works expected.

thanks reading hope can me. fyi not thoroughly experienced in js, , might missing major concept.

  setstateinchunks(newstate, _this) {      var obj = {};      obj = newstate.tostring();      var newobj = eval(obj);     _this.setstate({view: newobj});  } 

this example class object being set state

const react = api.react; const reactbootstrap = api.reactbootstrap;  // bootstrap elements const row = reactbootstrap.row; const col = reactbootstrap.col; const = reactbootstrap.well; const button = reactbootstrap.button; const buttongroup = reactbootstrap.buttongroup;  var examplevar = null;  // initialize namespace const namespace = 'examplestring';  class view extends foo.bar {    constructor() {     super();      this.namespace = namespace;      examplemodule = foo.bar('examplestring');   } } 

edit: setstateinchunks() function being called in place of standard this.setstate() in parent component. used this

var newview = foo.getview('storedview') this.setstateinchunks(newview, _this);


Comments