Checkbox is a common component that we often use on UI. We do have some cool ones How to display checkbox in reactnative.
The core react-native package does not support checkboxes, you need to install one software package to use it.
The following packages must be installed to display checkboxes-
npm install --save-dev react-native-paper
The basic checkbox components are as follows-
<Checkbox status={checkboxstatus} onPress={onCheckboxCheckedfunc} />
Now let’s look at some of the checkboxes Important Properties-
Props th> | Description |
---|---|
The value that can be set to give the status is Checked, unchecked, and undefined. | |
The value is a boolean. Can be used as Enable/disable checkbox. | |
Function that will be called when the button is pressed The checkbox is checked. | |
The color assigned to the checkbox | |
< /td>Unchecked checkbox s color |
const [checked, setChecked] = React.useState(false);
onPress={() => { setChecked(!checked); }}
import * as React from 'react'; import { StyleSheet, Text, SafeAreaView } from 'react-native'; import { Checkbox } from 'react-native-paper'; const MyComponent = () => { const [checked, setChecked] = React.useState(false); return ( <SafeAreaView style={styles.container}> <Checkbox status={checked ? 'checked' : 'unchecked'} onPress={() => { setChecked(!checked); }} color={'green'} uncheckColor={'red'} /> <Text>Checkbox</Text> </SafeAreaView> ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center' }, }); export default MyComponent;
The above is the detailed content of How to show checkbox in reactnative?. For more information, please follow other related articles on the PHP Chinese website!