Home > Software design >  What's a type for any valid JSX attribute?
What's a type for any valid JSX attribute?

Time:01-21

Looking for a definition for AnyValidAttributes in:

const Component = (props: AnyValidAttributes) => (
  <div {...props}>
    example
  </div>
)

CodePudding user response:

"ReactNode" should be valid for any JSX attribute.

CodePudding user response:

Your component is rendering a div, and you are passing props to it. The more generic and yet safe type of props would be HTMLAttributes<HTMLDivElement>:

import { HTMLAttributes } from "react";

const Component = (props: HTMLAttributes<HTMLDivElement>) => (
  <div {...props}>example</div>
);
  • Related