Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda