【发布时间】:2021-10-04 08:26:54
【问题描述】:
我有 2 个 TouchableOpacity,每个都有一个 View。
我需要在按下 TouchableOpacity 时将 View 的 backgroundColor 更改为蓝色,并在第二次按下其 TouchableOpacity 时返回初始 backgroundColor。
这里我不想使用状态,因为我有 2 个或更多的 TouchableOpacity,所以我需要为每个组件都有一个状态。
这是我的代码:
<TouchableOpacity>
<View style={{backgroundColor:'green'}}>
</View>
</TouchableOpacity>
<TouchableOpacity>
<View style={{backgroundColor:'yellow'}}>
</View>
</TouchableOpacity>
【问题讨论】:
-
Check this answer here(抱歉,声誉不足,无法发表评论)
标签: javascript reactjs react-native jsx