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

411
Views
I am getting my output on my console , but cannot get it on screen . Its a code, which counts no. of characters on input string

enter image description here Its a program , which counts no. of characters on input string. everything is coming correct on console, but i am not able to get it on UI. I have tried getting count.valueOf() , but it doesnot seems right.

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 }, [])
        setPrint(false)
        console.log(result)
        return result      
    }

    const clickHandler=()=>{
        setPrint(true)
    }

  return (
    <div>
        <input type="text" value={data} onChange={ e=> setData(e.target.value)}/>
        <div><button onClick={clickHandler}>CLICK!</button></div>
        
    {
     print?
      <h1> 
            {count(data)}
      </h1> : ""
    }
    </div>
  )
}

export default CharCount

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

count(data) return an array , try this

print && (
  <>
    count(data).map(val => (<h1>{val}</h1> )) 
  </>
)
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!