Skip to content
Advertisement

Share QR React Native

I’m new in react/react native. I’m trying to share a QR Code as image. Generate QR works, but I want to share it as an image (whatsapp, bluetooth, etc).

JavaScript

I tried “get base64 string encode of the qrcode” from official documentation, but I just don’t get it

JavaScript

What I tried to do (all my code):

JavaScript

get error svg.toDataURL is not a function. I have been in this for days, I also read another stackover queries with the same problem but solutions in those questions didn’t work for me. Thank you in advance guys

Error toDataURL

console.log(svg)

Advertisement

Answer

I have changed a couple of things in your code and used it on a expo app where I installed react-native-qrcode-svg and react-native-svg

JavaScript

Main changes from your code is defining the callback as a function

JavaScript

and doing the call properly on getDataURL

JavaScript

After those changes clicking in the button returns the dataURL in the console as expected.


Old answer before question edit:

Your issue seems to be that svg is not defined when you call svg.toDataURL how are you calling the function? If you are doing that on the first render it is possible that the ref is not ready yet.

If you are doing that using a callback in a button in the screen then the issue should be around the code setting the ref.

Can you post your whole component?

Advertisement