I’m using TypeScript with React Native to develop a mobile app.
To restore the scroll position of the previous screen, I created a variable and assign the useRef()
to handle the scroll.
What is the type for the ref prop?
I’ll share my code below.
const sectionListRef = useRef();
...
sectionListRef.current.ScrollToLocation // <-- Property 'scrollToLocation' does not exist on type 'never';
I have no idea which type should be…
Can someone please tell me why this error happens and how I resolve this?
2
Answers
This syntax maybe help you:
For example:
You should specify type and initial value.
I did find a similar solution for
FlatList
, perhaps try if this could help:When using
.scrollToLocation()
:More about
scrollToLocation
I couldn’t find any offical guide for this though, but hopefully these would help as a reference.