I'm using https://www.npmjs.com/package/react-native-link-preview this library to fetch meta data from url's. I have tried it and it's working for me. I'm trying to assign the value in the promise to a variable but i cannot get it to work. How can it to a variable.
My code
if(this.videoUrl != null){
LinkPreview.getPreview(this.videoUrl)
.then(data =>
console.log("previewData ",data)
);
}
Here i want to use the values in data . I've tried declaring a variable and assign the value to it. But it was getting a null value. So how can i do it.
My approach
var previewData = '';
if(this.videoUrl != null){
LinkPreview.getPreview(this.videoUrl)
.then(data =>
previewData = data,
console.log("previewData ",previewData)
);
}