How about:
import type { HTMLProps } from "react";
type Props = Pick<HTMLProps<HTMLElement>, "className">
class MyComponent extends React.Component<Props, {}> { }
// Or:
function MyComponent(props: Props) { }
Of course you can use {className?: string} as suggested by others, but using the method above gives you the ability to easily add other standard props as well, including children from React.
import type { HTMLProps } from "react";
type Props = Pick<HTMLProps<HTMLElement>, "className" | "children">
function MyComponent({className, children}: Props) {
return (<div className={className}>{children}</div>);
}
You can also be more specific:
import type { ComponentProps } from "react";
type Props = Pick<ComponentProps<'div'>, "className" | "children", "title">
function MyComponent({className, children, title}: Props) {
return (
<div className={className} title={title}>
{title && <h1>{title}</h1>
{children}
</div>
);
}
and of course, you can extend with anything you like:
import type { ComponentProps } from "react";
type Props = Pick<ComponentProps<'div'>, "className" | "children"> & {
count: number;
}
function MyComponent({className, children, count}: Props) {
return (
<div className={className} title={title}>
{count && <h1>{count}</h1>
{children}
</div>
);
}
In other words, it's a more useful way generally, so why not use get used to using it as a pattern?