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

100
Visualizações
How to pass onChange event inside template literal in react

Im trying to pass an onChange event inside a template literal in a react project. I have some inputs and im trying to change the value based on what the user typed in and for now just print it out inside of paragraph element, my end goal is to save all input information and print it out inside of a new card.

This is my attempt and code

const [title, setTitle] = useState("")


    let output = `<div class="card create-card">
            <div class="card-image"></div>
          <div class="card-text card-text-area">
              
              <h2>Create new spot</h2>
              <form>
              <label>Spot title</label>
              <input
              required
              value="${title}"
              onChange="${(e) =>{setTitle(e.target.value)}}"
              type="text" 
              >
              </input>
            
              <button>Add card</button>

              <p>${ title }</p>
          </div>
          </div>`;

It seems like its an easy fix but cant really find the right syntax when used inside of a template literal.

I dont get any errors nor no output

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

this might work declare your function before your output and pass it

const changeHandler = (e) =>{setTitle(e.target.value)};
.
.
.
onChange="${changeHandler(e)}"
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