[英]React Native access variable
I want to access to different variables with indexing.我想通过索引访问不同的变量。
first I created them:首先我创建了它们:
const refRBSheet0 = useRef();
const refRBSheet1 = useRef();
const refRBSheet2 = useRef();
const refRBSheet3 = useRef();
const refRBSheet4 = useRef();
and now I want to access them with something like:现在我想通过以下方式访问它们:
onPress={() => [refRBSheet + index].current.open()}
or或者
onPress={() => {refRBSheet + index.toString}.current.open()}
but none of them works for me.但它们都不适合我。
You can create arrays of refs and use based on index.您可以创建参考的 arrays 并根据索引使用。
const refRBSheet = [useRef(),useRef(),useRef(),useRef(),useRef()]
onPress={() => refRBSheet[index].current.open()}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.