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

139
Views
No puedo escribir línea por línea para enviar mensaje (Reaccionar, HTML)

(perdón por el mal inglés) Estoy codificando una aplicación de chat usando React, pero cada vez que intento enviar un mensaje línea por línea (shift + enter para una nueva línea), no funciona. Solo deja espacios. Pero presiono dos veces para shift+enter, funciona Ejemplo: presiono shift+enter una vez:

área de texto:

 Line 1 Line 2

después de enviar el mensaje:

 Line 1 Line 2

Presiono shift+enter dos veces (Funciona pero no quiero esto):

área de texto:

 Line1 // 1 line blank Line2

mensaje:

 Line1 Line2

Pero odio esto. Por favor ayúdenme :( Aquí está el código:

REACCIONAR:

 <textarea onInput={() => autoGrow} onChange={(e) => { setMessage(e.target.value); }} autoComplete="off" onKeyDown={sendMessage} type="text" className="overflow-y-auto rounded-l-2xl outline-none h-12 bg-dark-200 pt-3 text-white pl-4 justify-center resize-none flex items-center" placeholder="Text A Message" id="message-input" style={{ width: "90%", backgroundColor: "#323232" }} > </textarea>

JavaScript:

 // States let [messages, setMessages] = useState([]), [ message, setMessage ] = useState(""); async function sendMessage(e) { if (e.keyCode === 13 && !e.shiftKey) { e.preventDefault(); if (message.replace(/\s/g, "") === "") { return; } else { let data = { content: message.trim(), createdTimestamp: moment().locale("fr-FR").calendar(), id: generateID(), }; setMessages([...messages, data]); setMessage(""); e.target.value = ""; } } else { setMessage(e.target.value); } }

about 4 years ago · Juan Pablo Isaza
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!