Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: setState(). Can only update a mounted or mounting component #21

Closed
elie222 opened this issue May 28, 2016 · 16 comments
Closed

Comments

@elie222
Copy link
Contributor

elie222 commented May 28, 2016

I get this warning after logging in on iOS:
Warning: setState(). Can only update a mounted or mounting component

@spencercarli
Copy link
Owner

Hmm good catch. @Umar-Abbas would you want to take a look at this?

@Sivli-Embir
Copy link

+1

1 similar comment
@dvolland
Copy link

+1

@martwetzels
Copy link

martwetzels commented Jul 18, 2016

Running into the same issue, anyone managed to solve this? I only get this error when invalid credentials are submitted by Meteor.loginWithPassword()

@spencercarli
Copy link
Owner

Made updates in #39 and didn't see this happening any more. Let me know if that's not the case!

@dvolland
Copy link

Unfortunately it is still not working for me. I still cant get past creating an account, because I get this message. Updated to the newest version of the boilerplate. Using react-native: 0.30.0, Meteor 1.3.5.1and iOS 9.2 Simulator.

@spencercarli spencercarli reopened this Jul 25, 2016
@elie222
Copy link
Contributor Author

elie222 commented Jul 31, 2016

This is still happening:
screen shot 2016-07-31 at 11 13 28 am

Why are we using setState at all? I thought you preferred stateless components in your tutorials?

I'm going to be working on this myself now in any case

@elie222
Copy link
Contributor Author

elie222 commented Jul 31, 2016

It only happens when signing in with an email address that doesn't exist I believe. But the screen is littered with warnings in any case of all different types.

@spencercarli
Copy link
Owner

Not sure why it's taken me this long to realize but the setState error is a result of this line and this one.

What's happening is that when you press sign in/up with incorrect values the callback is being handled and setting the error state. The problem here is that when you press login/createAccount you set Meteor.loggingIn() to true, thus showing the Loading component.

I'll do some thinking around how to fix this - at least now we know where the problem is originating from!

@spencercarli
Copy link
Owner

@elie222 as for the usage of setState - it's being used because I haven't incorporated a library like redux in (intentionally for simplicity's sake). And I typically only use minimongo-cache as read-only.

In an ideal world (like in production apps) we would use a single global store, like Redux, to keep all of our state but that's got a larger learning curve involved.

@spencercarli
Copy link
Owner

Also, @elie222, what other warnings/errors are you seeing? If they're unrelated to this one please open a new issue! I want to make sure everything is working well 😄

spencercarli added a commit that referenced this issue Aug 7, 2016
@spencercarli spencercarli mentioned this issue Aug 7, 2016
spencercarli added a commit that referenced this issue Aug 7, 2016
@spencercarli
Copy link
Owner

Should be good to go now 👍

@elie222
Copy link
Contributor Author

elie222 commented Aug 29, 2016

Cool. Thanks!

@elie222
Copy link
Contributor Author

elie222 commented Aug 29, 2016

I just realised there's still a problem here. Sometimes it shows the error, and sometimes the screen just flashes and the email/password field just go blank with no error message shown.

Seems like the issue is due to what you wrote above:

What's happening is that when you press sign in/up with incorrect values the callback is being handled and setting the error state. The problem here is that when you press login/createAccount you set Meteor.loggingIn() to true, thus showing the Loading component.

The screen loads, the component gets unmounted, and all state is wiped.

@elie222
Copy link
Contributor Author

elie222 commented Aug 29, 2016

My current hacky/fix is changing this line:
if (status.connected === false || loggingIn) {
To:
if (status.connected === false) {
in the main index.js file.

But now you get a flash of the login screen when you open the app and you're logged in, so that's not great either.

@spencercarli
Copy link
Owner

@elie222 opened up a new issue to handle that (since it's slightly different from this) #53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants