首页 > 解决方案 > 如何使用功能组件访问 ref react native

问题描述

我有一个功能组件,我试图从平面列表中的视图获取 ref,因为我试图使用 expo 中的 takeSnapshotAsync(view, options) 函数,我需要访问该视图以将其传递给 expo 函数,任何帮助很重要。

<FlatList
          data={images}
          keyExtractor={(images) => images.created_at}
          renderItem={({ item }) => { 

            return (
              <View style={{ borderRadius: 15, overflow: 'hidden', marginLeft: 0 }} ref={ref => {
                const viewRef = ref}}>

标签: react-nativeexpo

解决方案


您可以使用useRef,如此处所述:https ://reactjs.org/docs/hooks-reference.html#useref


推荐阅读