我有两个组成部分 组件A默认具有一个隐藏的按钮,而另一个组件 有搜索按钮的B 当我单击组件B中的按钮时如何使组件A中的按钮可见 我要在A中导入组件B 如何实现上述提及?
答案 0 :(得分:0)
激活按钮时,有许多方法可以浮动其他组件。
您可以更改状态值以使其浮动, 或者,您可以通过键值传递值以接收数据并执行按钮, 如下例所示。
example.js
<TouchableOpacity
onPress={() => this.getItems()}
activeOpacity={0.5}
style={styles.btn}
textStyle={styles.txt}
>Get Products ({productList.length})</TouchableOpacity>
{
productList.map((product, i) => {
return (
<View key={i} style={{
flexDirection: 'column',
}}>
<Text style={{
marginTop: 20,
fontSize: 12,
color: 'black',
minHeight: 100,
alignSelf: 'center',
paddingHorizontal: 20,
}} >{JSON.stringify(product)}</Text>
<TouchableOpacity
onPress={() => this.buyItem(product.productId)}
activeOpacity={0.5}
style={styles.btn}
textStyle={styles.txt}
>Buy Above Product</TouchableOpacity>
</View>
);
})
}