Struggling to make this work, facing the same error repeatedly. Since I am still new to Typescript, a breakdown of what this error message signifies would be greatly appreciated:
const itemsRef = useRef<Array<HTMLLIElement | null>>([]);
...
<li
ref={(el) => (itemsRef.current[index] = el)}
/li>
The error message reads as follows:
Type '(el: HTMLLIElement | null) => HTMLLIElement | null' is not assignable to type 'LegacyRef<HTMLLIElement> | undefined'.
Type '(el: HTMLLIElement | null) => HTMLLIElement | null' is not assignable to type '(instance: HTMLLIElement | null) => void | (() => VoidOrUndefinedOnly)'.
Type 'HTMLLIElement | null' is not assignable to type 'void | (() => VoidOrUndefinedOnly)'.
Type 'null' is not assignable to type 'void | (() => VoidOrUndefinedOnly)'.