I am uploading an image in a form and the form is getting submitted to Firebase Database and I also want to send along the image URL to Firebase Database.
var {image} = this.state;
var {url} = this.state;
var that = this;
var storageRef = firebase.storage().ref('students_images/' + image.name);
storageRef.put(image).then(function(snapshot) {
  that.setState({
    url: snapshot.downloadURL
  });
});
var studRef = firebaseRef.child('students');
var newStudRef = studRef.push().update({
  name: val['name'].value,
  email: val['email'].value,
  age: val['age'].value,
  date: val['jdate'].value,
  course: val['course'].value,
  imgUrl: url
});But the problem is that the image URL is coming from an asynchronous function and it takes a little bit giving back the URL, but the form is getting submitted immediately, so the value of imgUrl is setting undefined.
 
     
     
    