2

React 0.14.0 & Vanilla Flux

I'm simply doing a check if the user is logged in and if so I'll display their stuff, else I'll show a loading page.

Once the user is loaded in the store a "_onChange" is triggered and "getStateFromStores" will update the user from null to an object.

render: function() {
   if(this.state.user !== null){
     //Stuff that will be rendered
   }
   else{
       <div>Loading...</div>
   }

Yet this if statement will throw an error because this.state.user will be null the first time it checks

Uncaught (in promise) TypeError: Cannot read property '_currentElement' of null

Is there a way to do this type of checks or will I have to create a "userLoaded" boolean or something?

Nick Pineda
  • 6,354
  • 11
  • 46
  • 66
  • code you shared looks fine, and looks completely unrelated to your error. What's `_currentElement`? What promise? Why do you think that the error is caused by `this.state.error` being null? – wintvelt Nov 01 '15 at 08:59
  • @wintvelt When I add in "this.state.user !== null" it fails, when I take it out i works, and it fails on that line most likely because "user" is initially null. – Nick Pineda Nov 01 '15 at 19:27
  • hmm strange.. have you looked [here](http://stackoverflow.com/questions/29786154/upgrading-react-to-0-13-2-causes-uncaught-typeerror-cannot-read-property-cu)? (others have had strange errors like this apparently). Again, your statement looks fine. Even if `this.state.user` is null, then your code should not throw this error.. – wintvelt Nov 01 '15 at 19:46
  • @wintvelt ... you were right! It should be working fine. I just made a false negative goof cause it was late last night. Very sorry but I appreciate the help soooo much! – Nick Pineda Nov 01 '15 at 19:49

0 Answers0