为什么我得到这个错误?
(property) ref: React.RefObject<FlatList<any>>
Type '{ ref: RefObject<FlatList<any>>; data: IInstructionsData[]; renderItem: ListRenderItem<IInstructionsData>; ... 6 more ...; showsHorizontalScrollIndicator: false; }' is not assignable to type 'IntrinsicAttributes & { ItemSeparatorComponent?: ComponentType<any> | AnimatedNode<ComponentType<any> | null | undefined> | null | undefined; ... 146 more ...; simultaneousHandlers?: Ref<...> | ... 2 more ... | undefined; } & { ...; } & { ...; }'.
Property 'ref' does not exist on type 'IntrinsicAttributes & { ItemSeparatorComponent?: ComponentType<any> | AnimatedNode<ComponentType<any> | null | undefined> | null | undefined; ... 146 more ...; simultaneousHandlers?: Ref<...> | ... 2 more ... | undefined; } & { ...; } & { ...; }'.ts(2322)
代码:
import Animated, { useAnimatedScrollHandler, useSharedValue, useDerivedValue, useAnimatedRef } from 'react-native-reanimated';
const AnimatedFlatlist = (Animated.createAnimatedComponent(
FlatList
) as unknown) as <T>(props: RNGHFlatListProps<T>) => React.ReactElement;
<AnimatedFlatlist
ref={flatlistRef}
data={mockData}
renderItem={renderItem}
onScroll={handleScroll}
keyExtractor={(item, i) => i.toString()}
initialNumToRender={2}
keyboardShouldPersistTaps='handled'
horizontal
pagingEnabled
showsHorizontalScrollIndicator={false}
/>
在ref
上的AnimatedFlatlist出现错误我做错了什么,我该如何解决这个问题?
您的代码片段不完整。你在哪里定义了AnimatedFlatList的ref ?
应该是这样的:
const flatListRef = useRef<FlatList<T>>(null);