Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6288

DraggableFlatList onRef getting a wrong type with Typescript

$
0
0

I am using react-native-draggable-flatlist in ReactNative. I am interested in the ref to FlatList so that I can perform a scrollToIndex on it. Using the following code:

import React, {    useEffect, createRef, useRef,} from 'react'import { ScrollView, FlatList } from 'react-native-gesture-handler'import DraggableFlatList, {    RenderItemParams, DragEndParams,} from "react-native-draggable-flatlist"export default function TasksList(props: Props) {    const ref = createRef<DraggableFlatList<ITask>>()    const flatListRef = useRef<FlatList<ITask> | null>(null)    return (<DraggableFlatList            ref={ref}            onRef={flatListRef}...    )}

I get the following Typescript error:

Type 'MutableRefObject<(ComponentClass<FlatListProps &NativeViewGestureHandlerProps & RefAttributes, any> & { ...; }) |(FunctionComponent<...> & { ...; }) | null>' is not assignable to type'(ref: RefObject<FlatList>) => void'. Type'MutableRefObject<(ComponentClass<FlatListProps &NativeViewGestureHandlerProps & RefAttributes, any> & { ...; }) |(FunctionComponent<...> & { ...; }) | null>' provides no match for thesignature '(ref: RefObject<FlatList>): void'.The expected type comes from property 'onRef' which is declared hereon type 'IntrinsicAttributes &IntrinsicClassAttributes<DraggableFlatList> &Pick<Readonly<Modify<FlatListProps, { ...; } & Partial<...>>> &Readonly<...>, "ItemSeparatorComponent" | ... 150 more ... |"children"> & Partial<...> & Partial<...>'

How to fix the error so that I can use the ref/ onRef?


Viewing all articles
Browse latest Browse all 6288

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>