I created a reference like so for the animation on a circle svg:
const circleRef = useRef(null);
And in a useEffect
, I have this line of code which is producing the error:
circleRef.current!.setNativeProps({
strokeDashoffset,
});
This is the produced error message:
Property 'setNativeProps' does not exist on type 'never'.
Any ideas as to why this is happening? Seems like a typing error to me, but I could be wrong
TypeScript doesn't know the type of the ref that will be held by
circleRef
since no type argument is given and the initial value isnull
. The inferred type is thennever
.You can simply do:
I would also recommend to use the
?
operator instead of the!
operator to prevent a crash if the ref ever happens to not be defined when this code runs: