I'd like to set a progress bar in my react code:
class imageUpload extends Component {
constructor(props) {
super(props);
this.state = {
image: null,
url: '',
progress: 0
}
I have progress in my state.
upload = (image) => {
ImageTools.resize(image, {
width: 320, // maximum width
height: 240 // maximum height
}, function(blob, didItResize) {
document.getElementById('preview').src = window.URL.createObjectURL(blob);
const uploadTask = storage.ref(`images/${image.name}`).put(blob);
uploadTask.on('state_changed',
(snapshot) => {
// progrss function ....
const progress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
this.setState({progress}); // Unhandled Rejection (TypeError): Cannot read property 'setState' of undefined
},
when I select an image and upload it, it is going to server, but I get this error:
Unhandled Rejection (TypeError): Cannot read property 'setState' of undefined
html
<progress value={this.state.progress} max="100"/>
any ideas why?
thanks!