I got this error:
Type 'ForwardedRef<unknown>' is not assignable to type 'LegacyRef<HTMLDivElement>'
import React from "react";
const Other = React.forwardRef((props, ref) => {
return (
<div ref={ref}>
<h1>Other</h1>
</div>
);
});
export default Other;
Is this the right usage?
Demo: https://codesandbox.io/s/summer-shadow-5ul13e?file=/src/Other.tsx:0-172
Simply make sure to provide type arguments to forwardRef
, as shown for example here:
import React from "react";
const Other = React.forwardRef<HTMLDivElement, unknown>((props, ref) => {
return (
<div ref={ref}>{/* Okay */}
<h1>Other</h1>
</div>
);
});
Playground Link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With