Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
How to make an Es6 react program to count number of letters in string in input box ? I have tried above code, but am not able to show on UI

enter image description hereIn console, i am able to see the output, but on screen, it's not coming. How to input the string from user on input box, then show the results on screen? Is something wrong with the logic? Is there any better method?

import React, { useState } from 'react'

const CharCount = () => {

    const [data, setData] = useState([])
    const [print, setPrint] = useState(false)

    const count= (value)=>{
       const result = [...value].reduce((a, e) => { a[e] = a[e] ? a[e] + 1 : 1; return a }, [])
        console.log(result, typeof(result))
        return result
}
   const getData=(e)=>{
    setData(e.target.value)
    setPrint(false)
   }

  return (
    <div>
        <input type="text" value={data} onChange={getData}/>
        <button onClick={()=>setPrint(true)}>CLICK!</button>
    {
     print ? count(data):"error"
    }
    </div>
  )
}

export default CharCount
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda