Created
September 11, 2019 05:27
-
-
Save overengineered/ae674879baa1b082308e7d759708b13d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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