如何选中/取消选中圆圈按钮作为我的例子? 这是我试图理解的例子
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
如果有什么线索可以告诉我理解的方法? 示例如上
const NewPlaceScreen = props => {
const [selectedCheckbox, setSelectedCheckbox] = useState(null);
const handlePress = title => {
selectedCheckbox === title ? setSelectedCheckbox(null) : setSelectedCheckbox(title)
}
...
}
CheckBox
组件的示例
<CheckBox
iconRight
right
title='oshea'
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={selectedCheckbox === 'oshea'}
onPress={() => handlePress('oshea'))}
/>