Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!