react-native - 如何使用功能组件访问 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}}>
解决方案
您可以使用useRef
,如此处所述:https ://reactjs.org/docs/hooks-reference.html#useref
推荐阅读
- c++ - 从 CMake 在 Eigen 中设置最大静态对齐
- excel - 如何使循环检查,总结单元格值并停在正确的位置
- c - c中的变量随机改变值
- racket - 如何在 Racket 中制作 HTML 表格边框
- vb.net - 如何计算已在 VB.NET 中的 datagridview 中检查的复选框
- microservices - jhipster 注册中心/控制中心向网关应用程序发送管理请求导致 401 未授权
- html - 为什么不使用填充作为显示?
- python - 我可以将 python 服务器与 kotlin 客户端连接起来吗?
- java - 我如何检测是否有人输入了错误的 otp
- r - 如果使用融化的 data.table,如何使用 ggplot2 向条形图添加标签?