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

252
Visualizações
Call a component's onChange method inside another one in React

There is a Selector component of this form:

<Selector
  initialSelectedOption={data[0].type}
  onChange={(val) => changeValue(val.name)}
  options={valueOptions}
/>;

when the user selects a value from the dropdown, onChange is called and the value is updated in the selector.

I want to reset the value to the original one once the user has clicked cancel:

 <Button onClick={handleCancel} />
...

  const handleCancel = () => {
    changeValue(data[0].type);
  };

However, something is wrong here as it is not called.

Is it a way to call the Selector's onChange method from handleCancel?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

We need a bit more context to know for sure, but in general, you should define onChange in a parent component and pass it as a prop to both the selector component and the component that handles the cancel.

about 4 years ago · Juan Pablo Isaza Relatório
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