0
render() {
    console.log(this.state.myStateValue); // I see this on the console
    var test = configOptions ? 
    Object.keys(configOptions).map(function(key) {
        console.log('test'); // I see this on the console
        console.log(this.state.myStateValue);  // Getting Uncaught TypeError: Cannot read property 'state' of undefined
    }
    return() {...}
}

What am I doing wrong?

Thanks!

erikvimz
  • 4,847
  • 6
  • 42
  • 57
Testaccount
  • 2,585
  • 3
  • 20
  • 24

1 Answers1

2

Try this:

Object.keys(configOptions).map(function(key) {
    console.log('test'); 
    console.log(this.state.myStateValue); 
}.bind(this))

or better, if you have ES6:

Object.keys(configOptions).map((key) => {
    console.log('test');
    console.log(this.state.myStateValue); 
})
Mayank Shukla
  • 92,299
  • 16
  • 152
  • 142
pscl
  • 3,128
  • 23
  • 28