Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
qr code shows up immediatly before i click the button reactjs

im using react-qr-code package for generating qr code but the problem is it renders immediately instead of after clicking the submit button so for that, i want a function that can render the qr code after clicking the button i don't know what a should do i try slit it to components but still the same

import React from 'react';
import './QrCodeInfo.css';
import QRCode from "react-qr-code";

import { useState } from 'react';

function QrCodeInfo(props) {
   


  const [wifiName, setWifiName] = useState('');
  const [password, setPassword] = useState(''); 

const clickButton=()=>{
    let qrimage = password
    return (qrimage)
}


    return(
<div className='center'>
<div className=" center card shadow">
<div className='flex'>
<form>
    <div className="user-details">

              <div className="input-box">
                <span className="details">WifiName</span>
                <input type="text" placeholder="Enter your WifiName"  value={wifiName}
                   onChange={event => setWifiName(event.target.value)} required/>
              </div>
              <div className="input-box">
                <span className="details">Password</span>
                <input type="text" placeholder="Enter your Password" value={password}
                    onChange={event => setPassword(event.target.value)} required/>
              </div>
              </div>
              <div className='center'>
              <button type='button'className='center' onClick={clickButton}> Submit
               </button>
               </div>
</form>
<div>

<h1 >{wifiName}</h1>
<QRCode value='' />
</div>
</div>
</div>
</div>





        )

}

export default QrCodeInfo;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Because you just render the QRCode component without any condition. You can try this when the password has value and the user click the button. Show the QR code.

import React from "react";
import QRCode from "react-qr-code";

import { useState } from "react";

function QrCodeInfo() {
  const [wifiName, setWifiName] = useState("");
  const [password, setPassword] = useState("");
  const [qrCodeVisible, setQrCodeVisible] = useState(false);

  const clickButton = () => {
    let qrimage = password;
    setQrCodeVisible(!!qrimage);
  };

  return (
    <div className="center">
      <div className=" center card shadow">
        <div className="flex">
          <form>
            <div className="user-details">
              <div className="input-box">
                <span className="details">WifiName</span>
                <input
                  type="text"
                  placeholder="Enter your WifiName"
                  value={wifiName}
                  onChange={(event) => setWifiName(event.target.value)}
                  required
                />
              </div>
              <div className="input-box">
                <span className="details">Password</span>
                <input
                  type="text"
                  placeholder="Enter your Password"
                  value={password}
                  onChange={(event) => setPassword(event.target.value)}
                  required
                />
              </div>
            </div>
            <div className="center">
              <button type="button" className="center" onClick={clickButton}>
                Submit
              </button>
            </div>
          </form>
          <div>
            <h1>{wifiName}</h1>
            {qrCodeVisible && <QRCode value={password} />}
          </div>
        </div>
      </div>
    </div>
  );
}

export default QrCodeInfo;

Codesandbox

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda