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

86
Visualizações
Passing a function with less arguments to a react component which has a prop expecting a function with optional arguments

I have a react functional component which accepts a function with optional arguments. I need call this component passing a function having all the arguments in one parent component and with a function having only the required arguments in the other parent component. An example would be like this:

    interface Props {
      onValueChange?: (a, b, c?, d?) => void;
    }
    
    export const MyComponent = ({onValueChange}: Props) => {
    
      return (
        <InputField
          onChange={() => onValueChange(a, b, c, d)}
        />
      );
    }
    
    const FunctionWithCorrectArgsComp = () => {
      const f = (a, b, c?, d?) => {};
    
      return (
        <MyComponent
          onValueChange={f}
        />
      )
    }
    
    const FunctionWithLessArgsComp = () => {
      const f = (a, b) => {};
    
      return (
        <MyComponent
          onValueChange={f}
        />
      )
    }

I want to know when I do this it will cause any problem for the FunctionWithLessArgsComp when the onChange event is called on MyComponent.

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