I'm trying to find what to type React.createRef as. Header is a custom component. header.current always says
(property) React.RefObject.current: unknown Object is of type 'unknown'.
I can set it to type <any> but that's the easy way out. How do I get Typescript to play nice and stop complaining.
Example: React.createRef<any>()
Fully code:
const header = React.createRef();
const { container } = render(
<Header{...props} headerRef={header} />,
);
const el = header.current.getButtonElement("button");
I've even tried setting it to a HTMLDivElement which is what it returns.
const header = React.createRef<HTMLDivElement>();
but the below still gives me an error: (property) React.RefObject.current: HTMLDivElement | null Object is possibly 'null'.
const el = header.current.getButtonElement("button");