Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

76
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda