【发布时间】:2020-03-26 04:33:56
【问题描述】:
使用功能组件,我想到达我按下的目标元素,然后交互/更改它的值。现在我正在这样做(以样式参数为例),它有效。
但是...如果我有更多不同的元素,我该如何以更动态的方式做到这一点?
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>
);
};
【问题讨论】:
标签: react-native element target react-functional-component