I noticed your code has a bug though:
Using += to mutate API_URL is probably not what you intended:
letAPI_URL="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=";functiondataSubmit(e){if (inputText!==""){textPresent=true;API_URL+=inputText;// look at the result after making multiple submissions to see why this is bad:console.log(API_URL);}}
Instead you can simply make API_URL a const and append the input to it:
// this shouldn't ever change!constAPI_URL="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=";functiondataSubmit(e){if (inputText!==""){loadingQrCode=true;letimg=newImage();img.src=API_URL+inputText;// better ;)console.log(img.src);}}
hey Been, thanks for spotting that! Since this is a 1:1 translation, I usually don't review the code example, and seems I should've done to this one! :D I appreciate your effort, cheers
Cool to see people writing Svelte articles :)
I noticed your code has a bug though:
Using
+=
to mutateAPI_URL
is probably not what you intended:Instead you can simply make
API_URL
aconst
and append the input to it:hey Been, thanks for spotting that! Since this is a 1:1 translation, I usually don't review the code example, and seems I should've done to this one! :D I appreciate your effort, cheers
it is fixed, thanks mate!