Types for props in h / createElement function doesn't allow ref
- [ ] Check if updating to the latest Preact version resolves the issue.
Describe the bug:
h / createElement function doesn't allow ref in props, although code compiles successfully.
To Reproduce:
// DummyComponent.tsx
import { FunctionalComponent, h } from "preact";
import { useRef } from "preact/hooks";
const DummyComponent: FunctionalComponent = ({ children }) => {
const node = useRef<HTMLDivElement>();
return h("div", { ref: node }, children);
});
export default DummyComponent;
Error in VS Code:
Type 'MutableRef<HTMLDivElement | undefined>' is not assignable to type '(Ref<EventTarget> & Ref<SVGElement>) | undefined'.
Expected behavior: No errors.
~~I believe createRef is for classes, useRef is what you need in a functional component. The hooks docs mention making sure not to mix up createRef and useRef but maybe the ref docs could too.~~
Nevermind, it should at least accept the type in that scenario
Hello,
sorry, this was an oversight at my end. Updated my first post to useRef hook. Unfortunately, it does not solve this issue.
Error:
Type 'MutableRef<HTMLDivElement | undefined>' is not assignable to type '(Ref<EventTarget> & Ref<SVGElement>) | undefined'.
Thanks.