【发布时间】:2020-01-01 08:36:10
【问题描述】:
作为示例,如何选中/取消选中圆形按钮? 这是我试图理解的例子
import React, { useState } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { CheckBox } from 'react-native-elements';
const NewPlaceScreen = props => {
return (
<View>
<CheckBox
iconRight
right
title='poshea'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
onPress={() => setChecked6(prev => !prev)}
/>
<CheckBox
iconRight
right
title='oshea'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={() => setChecked7(prev => !prev)}
/>
</View>
);
};
NewPlaceScreen.navigationOptions = {
headerTitle: 'wiki'
};
const styles = StyleSheet.create({
TextStyle: {
fontWeight: 'bold',
color: 'grey'
}
});
export default NewPlaceScreen
如果有一些线索告诉我理解的方式? 上面的例子
【问题讨论】:
-
你混淆了
checked和onPress。checked是真还是假,需要引用一些状态。在此示例中,您需要创建两个状态变量checked6和checked7,方法与我们在您的其他问题中讨论的方式相同[stackoverflow.com/questions/59550755/…。然后将这两个值分配给您的checked道具。onPress在这种情况下对于您的第一个复选框是正确的,一旦您在组件顶部添加状态
标签: javascript reactjs react-native react-hooks