Skip to content

Instantly share code, notes, and snippets.

@overengineered
Created September 11, 2019 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save overengineered/ae674879baa1b082308e7d759708b13d to your computer and use it in GitHub Desktop.
Save overengineered/ae674879baa1b082308e7d759708b13d to your computer and use it in GitHub Desktop.
import React from 'react';
import {Button, SafeAreaView, Switch, Text, View} from 'react-native';
function CheckBox({value, label, onValueChange, testID}) {
return (
<View style={{flexDirection: 'row', justifyContent: 'space-between', padding: 10}}>
<Text>{label}</Text>
<Switch onValueChange={onValueChange} value={value} testID={testID}/>
</View>
);
}
export default function Example() {
const [awesome, setAwesome] = React.useState(false);
const [stunning, setStunning] = React.useState(false);
const sendData = () => {
fetch(server, {method: 'PUT', body: JSON.stringify({awesome, stunning})});
};
return (
<SafeAreaView>
<Text style={{fontSize: 20, fontWeight: 'bold', alignSelf: 'center'}}>React Native is:</Text>
<CheckBox value={awesome} label="Awesome" onValueChange={setAwesome} testID="awesome"/>
<CheckBox value={stunning} label="Stunning" onValueChange={setStunning} testID="stunning"/>
<Button title="Send" onPress={sendData} testID="submit"/>
</SafeAreaView>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment