【问题标题】:Change values of targeted element in React Native在 React Native 中更改目标元素的值
【发布时间】: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


    【解决方案1】:

    碰巧你需要从许多中选择一个。为此,我建议solution

    【讨论】:

      猜你喜欢
      • 2021-07-24
      • 2021-09-20
      • 2019-02-14
      • 1970-01-01
      • 2023-01-23
      • 2022-10-13
      • 2020-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多