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

248
Views
Reaccionar cómo establecer el valor de texto de conteo 0 para el cuadro vacío

En este momento, mi cuadro de texto vacío muestra el conteo 1. Vea la captura de pantalla a continuación:

ingrese la descripción de la imagen aquí

Quiero mostrar el valor 0 para el cuadro vacío. ¿como hacer eso? aquí está mi código:

 export default function TextFrom(props) { const handelUpClick = () => { let newtext = text.toUpperCase(); setText(newtext); }; const handelLoClick = () => { let newtext = text.toLowerCase(); setText(newtext); }; const handleOnChange = (event) => { setText(event.target.value); }; const [text, setText] = useState(""); return ( <> ..my html code <h1>your text summary</h1> <p> {text.split(" ").length} words and {text.length} character </p> <>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema aquí es que split devuelve [""] cuando se invoca en una cadena vacía, y la longitud de esa matriz es de hecho 1. Para contrarrestar esto, puede reemplazar la {text.split(" ").length} de su código con {text.trim() === '' ? 0 : text.split(" ").length} para que se solucione el caso en el que la entrada es solo un espacio en blanco.

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!