Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

react-native - 在React Native中更改目标元素的值(Change values of targeted element in React Native)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It happens that you need to choose one of many.

(碰巧您需要选择许多。)

For this I propose this solution .

(为此,我提出了这种解决方案 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...