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

63
Views
Change one charter in state while typing - reacjs

I have a state:

const [numIndexZero, setNumIndexZero] = useState("****");

And I have an input that I type 4 numbers.

How can I change each charter when i typing a number?

Meaning that, if I type "1" then the state will be "1***" .

If I type "12" then the state will be "12**" ,

If I type "123" then the state will be "123*" ,

If I type "1234" then the state will be "1234".

Any help??

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

0

You can do it by using padEnd methid like this:

<input onChange={(e)=>setNumIndexZero(e.target.value.padEnd(4,"*"))} .../>
about 4 years ago · Juan Pablo Isaza Report

0

Calling setState with the value directly updates the value. For eg:

setNumIndexZero('1***');
setNumIndexZero('12**');
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!