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?
CodePudding user response:
This syntax maybe help you:
For example:
const someRef = useRef<Your Type>(Your Initial Value);
You should specify type and initial value.
CodePudding user response:
I did find a similar solution for FlatList
, perhaps try if this could help:
const sectionListRef = useRef<SectionList>(null);
When using .scrollToLocation()
:
sectionListRef.current?.scrollToLocation(param);
I couldn't find any offical guide for this though, but hopefully these would help as a reference.