1

I get the error "variable uploadImageAsync cannot be found"

uploadImageAsync = async (uri) => {
  console.log("In upload image asnyc!");
}

And this is where I call it from.

_handleImagePicked = async pickerResult => {
let uploadResponse, uploadResult;

  this.setState({ uploading: true });

  if (!pickerResult.cancelled) {
    uploadResponse = await uploadImageAsync(pickerResult.uri);
    uploadResult = await uploadResponse.json();
    this.setState({ image: uploadResult.location });
  }
    this.setState({ uploading: false });
};

How can I get around this?

So far I've tried:

async function uploadImageAsync(uri) {

I've also tried:

async uploadImageAsync(uri) {
1
  • should you not add a const before uploadImageAsync? Commented Nov 18, 2017 at 12:53

1 Answer 1

5

If the uploadImageAsync function defined in the same component, you need call this.uploadImageAsync.

Otherwise, you must import it from the other module

or define the function outside the component in the same file.

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.