score:4

i figured out how to do it, here is the code:

import qrcode from 'qrcode.react';
constructor(props) {
    super(props);
this.download = this.download.bind(this);
}
componentdidmount(){
 this.download()
}
render() {
return (
 <div style={{display: "none"}} classname="hpqrcode"> // hidden div
   <qrcode
     value={this.state.values._id}
     size={128}
     level={'h'}
   />
 </div>
  <a ref={(ref: any): any => this.downloadref = ref}>
    download qr code
  </a>
)};
download() {
    const canvas: any = document.queryselector('.hpqrcode > canvas');
    this.downloadref.href = canvas.todataurl();
    this.downloadref.download = this.state.values.deviceid + "-qr.png";
}

Related Query

More Query from same tag