最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论