• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

137
Views
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>
  );
};
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

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>
  );
};
almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error