• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

149
Vistas
How to get event props in React component with rest operator?

I need some help. I am beginner in TS and i don't know how can i use my event props in my component. I defined two props and i need all my events as rest props.

I got an error when i use my component with onClick event.

Error: Property 'onClick' does not exist on type 'IntrinsicAttributes & ButtonProps'

I will be grateful for any help you can provide.

Here is my component:

export type ButtonProps = {
  children: React.ReactNode;
  className: string;  
};


export const Button = ({ children, className, ...rest }: ButtonProps) => {
  return (
   <button className={className} {...rest}>
     {children}
   </button>
  );
};
about 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do it like this using PropsWithChildren:

import { PropsWithChildren } from "react";

export type ButtonProps = {
  className: string;  
};


export const Button = ({ children, className, ...rest }: PropsWithChildren<ButtonProps>) => {
  return (
   <button className={className} {...rest}>
     {children}
   </button>
  );
};
about 3 years ago · Juan Pablo Isaza Denunciar
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda