useRef "refers to a value, but is being used as a type here."

Ilja picture Ilja · Apr 8, 2019 · Viewed 50.6k times · Source

I'm trying to figure out how to tell react which element is being used as ref i.e. in my case

const circleRef = useRef<AnimatedCircle>(undefined);

AnimatedCircle is an SVG component from a third party library, and defining it this way causes error

enter image description here

Is there some universal way to define which element is ref?

Answer

Ishmeet Singh picture Ishmeet Singh · Dec 17, 2019

In my case, I renamed the file as .ts instead of .tsx. Renaming it again fixed it.