【发布时间】:2020-02-06 09:31:04
【问题描述】:
我正在尝试使用功能组件中的 useRef 挂钩从 FlatList 访问 scrollToIndex() 方法或 scrollToItem() 方法。我希望能够在我的组件中使用flatListRef.current.ScrollToIndex(),类似于基于类的组件使用this.flatListRef.ScrollToIndex():
const flatListRef = useRef(React.createRef)
<FlatList
data={items}
renderItem={({ item }) => <Item item={item} />}
keyExtractor={item => item.id.toString()}
contentContainerStyle={styles.card}
horizontal={true}
showsHorizontalScrollIndicator={false}
ref={flatListRef}
/>
console.logging flatListRef.current 没有显示我正在寻找的上述方法。
【问题讨论】:
标签: reactjs react-native react-hooks