0

This is where I call register():

this.register();

Here's the register():

register = async () => {
    await login();
    await create();
}

Here are the ones I call:

login = () => {
    console.log('test');
}

Ideally, what I want is to finish login() first, then go to create().

Error I get:

Uncaught (in promise) ReferenceError: login is not defined

2
  • 3
    await this.login()? Commented Nov 30, 2018 at 22:47
  • 3
    The error means that at the moment you are trying to call login, it doesn't exist yet. You need to provide a minimal reproducible example for us to be able to tell you what is wrong. Commented Nov 30, 2018 at 22:48

2 Answers 2

1

As stated in the comments, you will probably need to complete the question with more context. In general, in Javascript, if you are working with classes, you will need to bind the context:

this.login = this.login.bind(this)

and then call this.login()

Moreover, in the case of react/redux, if your login function is not in your component you will probably have to connect your component and tell Redux what is the function you'll use, as explained here: Redux - call action from a function

Sign up to request clarification or add additional context in comments.

Comments

0

I had this issue when I was calling a normal function inside an Async function. Even though the async function was called directly on the button click, it still needed binding (this.function= this.function.bind(this)). The function I was calling did not need Binding itself, which wasn't consistent with what I've encountered before with binding.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.