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
  • 5,256
  • 6
  • 44
  • 60
Testaccount
  • 2,755
  • 3
  • 22
  • 27

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
  • 100,735
  • 18
  • 158
  • 142
pscl
  • 3,322
  • 25
  • 29