Svelte 3: Usando blocos "if"

Eduardo Rabelo on October 18, 2019

Aplicativos web aprimorados ciberneticamente Neste artigo, veremos como usar os blocos if com o Svelte para adicionar alguma lógica de ... [Read Full]
markdown guide

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

code of conduct - report abuse