reactjstypescriptreact-nativereact-hooks

Is there a way to know the exact type of props coming from a parent element in TypeScript?


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?


Solution

  • I did find a similar solution for FlatList, perhaps try if this could help:

    const sectionListRef = useRef<SectionList>(null);
    

    When using .scrollToLocation():

    More about scrollToLocation

    sectionListRef.current?.scrollToLocation(param);
    

    I couldn't find any offical guide for this though, but hopefully these would help as a reference.