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

134
Views
Call predefined method/function name dynamically from string value without explicitly calling the predefined name in ReactJS
export default function Projects() {
  const [p1, setp1] = useState(false);
  const [p2, setp2] = useState(false);
  const [p3, setp3] = useState(false);
  const [p4, setp4] = useState(false);
  const [p5, setp5] = useState(false);
  const [p6, setp6] = useState(false);

  function handleClose(k) {
    let x = "set" + k;
    window[x](false);
  }
  function handleShow(k) {
    let x = "set" + k;
    window[x](true);
  }

I am trying to call pre-defined methods/functions dynamically with the name passed as parameters to handleClose(k) and handleShow(k) as k by concatinating with another string for changing a specific state. window is not working nor self or this either. Is there any alternative that works in Reactjs

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!