0

I am trying to receive the return value of a method in another class with react-native.

ClassA.js

export default class ClassA{
    send(query) {
    var value = 1+query;
    return value;
  }
}

Trying to get value from class App.js

var value = ClassA.send(query);

This doesn't work however. I am receiving the following error:

ClassA.default.send is not a function, '_ClassA.default.send' is undefined

2
  • How are you importing ClassA? Commented Feb 8, 2019 at 18:52
  • @JoseVf import ClassA from './ClassA'; Commented Feb 8, 2019 at 19:12

1 Answer 1

1

you need to add static keyword to use as a class method,

export default class ClassA{
    static send(query) {
      var value = 1+query;
      return value;
    }
}

so you can access it with,

var value = ClassA.send(query);

or you can use it as a instance method;

export default class ClassA{
   send(query) {
     var value = 1+query;
     return value;
   }
}

and in this situation you can access that method from instance;

var instance = new ClassA();
var value = instance.send(query);
Sign up to request clarification or add additional context in comments.

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.