0

I'm stuck with setstate in reactjs. Initially I was implementing as

var versions = [1,2,3,4];
this.setState({
    options: versions
});

The above code is working fine in Google Chrome but in IE 10 and Firefox it not working.

Later I changed to :

var oState = {}
oState['options'] = versions;
this.setState(oState);

But the issue didn't resolved. Both the code is only working in Google Chrome not in other browsers.

Please do let me know how can I solve this issue.

David
  • 539
  • 3
  • 9
  • 23
  • both the ways are correct and will work also, issue is somewhere else. Can you show the code where you are doing this `setState` – Mayank Shukla Apr 25 '17 at 12:33
  • Hey Mayank, thank you for reply. I'm calling above code in plane function. The code will be executed once I call the function. I can't post you complete code as it very huge. Just let me know if you have any other options other than this. – David Apr 25 '17 at 12:38
  • check console are you getting any error ? if it is failing somewhere, it will log the error. – Mayank Shukla Apr 25 '17 at 12:39
  • Yes I tried all possible stuff to find where it's getting stuck. But the flow is very much clear. No error and log in console.. – David Apr 25 '17 at 12:42

1 Answers1

0

Have you tried to declare first your options in the state of the constructor?

constructor() {
  super();
  this.state = {
    options: null
  }
 }

But i'm not sure if it solves your problem.