Skip to content

Commit e906525

Browse files
Adriano Melofacebook-github-bot
Adriano Melo
authored andcommitted
Docs: Add example to CheckBox documentation
Summary: I find it easier to understand the behavior of a component when there is a simple example showing its usage. I recently used the CheckBox component and noticed that it doesn't have a code example. This PR adds an example to the CheckBox documentation. N/A [DOCS][ENHANCEMENT][CheckBox] - Added example to documentation Closes #16489 Differential Revision: D6260998 Pulled By: hramos fbshipit-source-id: 7c6f9677741a4c0483eb1f5405cd05f8bbdd83aa
1 parent 45ed142 commit e906525

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Libraries/Components/CheckBox/CheckBox.android.js

+44
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,50 @@ type DefaultProps = {
3434
* If the `value` prop is not updated, the component will continue to render
3535
* the supplied `value` prop instead of the expected result of any user actions.
3636
*
37+
* ```
38+
* import React from 'react';
39+
* import { AppRegistry, StyleSheet, Text, View, CheckBox } from 'react-native';
40+
*
41+
* export default class App extends React.Component {
42+
* constructor(props) {
43+
* super(props);
44+
* this.state = {
45+
* checked: false
46+
* }
47+
* }
48+
*
49+
* toggle() {
50+
* this.setState(({checked}) => {
51+
* return {
52+
* checked: !checked
53+
* };
54+
* });
55+
* }
56+
*
57+
* render() {
58+
* const {checked} = this.state;
59+
* return (
60+
* <View style={styles.container}>
61+
* <Text>Checked</Text>
62+
* <CheckBox value={checked} onChange={this.toggle.bind(this)} />
63+
* </View>
64+
* );
65+
* }
66+
* }
67+
*
68+
* const styles = StyleSheet.create({
69+
* container: {
70+
* flex: 1,
71+
* flexDirection: 'row',
72+
* alignItems: 'center',
73+
* justifyContent: 'center',
74+
* },
75+
* });
76+
*
77+
* // skip this line if using Create React Native App
78+
* AppRegistry.registerComponent('App', () => App);
79+
* ```
80+
*
3781
* @keyword checkbox
3882
* @keyword toggle
3983
*/

0 commit comments

Comments
 (0)