re: Svelte 3: Usando blocos "if" VIEW POST


Cool to see people writing Svelte articles :)

I noticed your code has a bug though:
Using += to mutate API_URL is probably not what you intended:

let API_URL = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=";
function dataSubmit(e) {
  if (inputText !== "") {
    textPresent = true;
    API_URL += inputText;
    // look at the result after making multiple submissions to see why this is bad:

Instead you can simply make API_URL a const and append the input to it:

// this shouldn't ever change!
const API_URL = "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=";
function dataSubmit(e) {
  if (inputText !== "") {
    loadingQrCode = true;
    let img = new Image();
    img.src = API_URL + inputText; // better ;)

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!

Code of Conduct Report abuse