Using a functional component, I want to reach the targeted element I pressed and so interact/change the value of it.
(使用功能组件,我想达到我按下的目标元素,因此可以交互/更改它的值。)
Right now I'm doing this (using style parem as example), and it works. (现在,我正在执行此操作(使用样式参数作为示例),并且它可以正常工作。)
But... how can I do it in a more dinamic way if I have much more different elements?
(但是...如果我有更多不同的元素,该如何以一种更生动的方式来实现?)
import React, { useState } from 'react';
import { View } from 'react-native';
const TestScreen = (props) => {
const [isA, setA] = useState(false);
const [isB, setB] = useState(false);
const [isC, setC] = useState(false);
return (
<View style={[isA ? styles.on : styles.off]} onPress={() => setA(!isA)}></View>
<View style={[isB ? styles.on : styles.off]} onPress={() => setA(!isB)}></View>
<View style={[isC ? styles.on : styles.off]} onPress={() => setA(!isC)}></View>
);
};
ask by ehijon translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…