0
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

piedpipr
  • 31
  • 4

0 Answers0