How to stop callback from unmounting component

Viewed 1009

Really confused here. I updated to React Router 4 which required a few changes and now when my registration form errors on the server side it returns the console error: this is the callback.

setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the RegisterForm component.

What's really confusing is if I run this.setState({ errors: {createUserError: "Test error" }}); outside of Accounts.createUser function I don't get the consolde error.

Any suggestions????

handleSubmit(event) {
    event.preventDefault();

    this.setState({errors: {} }, function() {
      var data = {
        email: this.state.email,
        password: this.state.password
      };

        Accounts.createUser(data, (error) => {   // This arrow function preserves this
        if(error) {
          this.setState({ errors: {createUserError: error.reason }});
        }
      });
    });
  }
1 Answers
Related