javascript - can't find variable function declaration react native - Stack Overflow

I get the error "variable uploadImageAsync cannot be found"uploadImageAsync = async (uri) =&g

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) {

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) {
Share Improve this question edited Nov 18, 2017 at 12:40 Andreas 21.9k7 gold badges51 silver badges58 bronze badges asked Nov 18, 2017 at 12:36 SwimmingGSwimmingG 6643 gold badges9 silver badges33 bronze badges 1
  • should you not add a const before uploadImageAsync? – vijayst Commented Nov 18, 2017 at 12:53
Add a ment  | 

1 Answer 1

Reset to default 5

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

Otherwise, you must import it from the other module

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745458615a4628603.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信