In my case, I want to change the image url to base64 file using the "base64-img" library.
I intend to save the results of converting the file into a state. I tried saving it to a variable also failed. I wrote the script as follows:
var base64Img = require('base64-img');
base64Img.requestBase64('url_image', function(err, res, body) {
this.setState ({ b64:body });
});
I get an error Uncaught TypeError: Cannot read property 'setState' of undefined
I try to set the value to a variable then console_log works well, but the value cannot be accessed from outside.
let b64;
base64Img.requestBase64('url_image', function(err, res, body) {
b64 = body;
console.log(b64);
});
I want to use the value b64 outside of the function. Thanks