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
1 Answer
Reset to default 5If 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.