I have a reusable wrapper component which like this:
import { FC, HTMLAttributes } from "react";
const Wrapper: FC<HTMLAttributes<HTMLDivElement>> = ({
children,
className,
...props
}) => (
<div className={`h-[90vh] ${className ? className : ""}`} {...props}>
{children}
</div>
);
export default Wrapper;
But I can't add the ref prop to the component.
<Wrapper ref={ref} ...
Property 'ref' does not exist on type 'IntrinsicAttributes & HTMLAttributes<HTMLInputElement>'.
What typescript type should I use for the Wrapper component and add the ref prop without an error?
If you would like to use
FCtype, then you'll need to useComponentPropsWithRef<"div">type for props. (don't forget to wrap component inforwardRefor ref won't work)Alternatively, you can omit
FCtype and just define component like this:This way you will be able to pass ref to the component and it will be typechecked.