Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from 'react';
- import { StatusBar } from 'expo-status-bar';
- import { StyleSheet, Text, View, Button, Alert } from 'react-native';
- const Cat = props => {
- const [isHungry, setIsHungry] = useState(true); // useState() here works as [getter, setter] and getter will change value..
- //..depending on what is done to setIsHungry
- return (
- <>
- <Text> I am {props.name}, and I am {isHungry ? 'hungry' : 'full'}!</Text>
- <Button
- onPress = {() => {
- setIsHungry(false);
- }}
- disabled = {!isHungry}
- title = {isHungry ? 'Pour me some milk, please!' : 'Thank you!'}
- />
- </>
- );
- };
- export default function App() {
- return (
- <View style = {styles.container}>
- <Cat name = "morris"/>
- <Cat name = "frasse"/>
- </View>
- );
- }
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: '#fff',
- alignItems: 'center',
- justifyContent: 'center',
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement