Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { useState } from 'react';
- import { Button, StyleSheet, Text, View } from 'react-native';
- const App = () => {
- const [joke, setJoke] = useState('');
- const getJoke = async () => {
- try {
- const response = await fetch('https://v2.jokeapi.dev/joke/Any?type=single');
- const data = await response.json();
- setJoke(data.joke);
- } catch (error) {
- console.error(error);
- }
- };
- return (
- <View style={styles.container}>
- <Button title="Get Joke" onPress={getJoke} />
- <Text style={styles.jokeText}>{joke}</Text>
- </View>
- );
- };
- const styles = StyleSheet.create({
- container: {
- flex: 1,
- justifyContent: 'center',
- alignItems: 'center',
- backgroundColor: '#fff',
- },
- jokeText: {
- marginTop: 20,
- fontSize: 20,
- textAlign: 'center',
- },
- });
- export default App;
Advertisement
Add Comment
Please, Sign In to add comment