// App.js
import React, { useState } from 'react';
import { View, Text, Button, StyleSheet } from 'react-native';
import axios from 'axios';

const App = () => {
    const [joke, setJoke] = useState('');

    const fetchJoke = async () => {
        try {
            const response = await axios.get('https://official-joke-api.appspot.com/random_joke');
            setJoke(`${response.data.setup} - ${response.data.punchline}`);
        } catch (error) {
            console.error(error);
            setJoke('Failed to fetch joke');
        }
    };

    return (
        <View style={styles.container}>
            <Text style={styles.header}>Random Joke Generator</Text>
            <Text style={styles.joke}>{joke}</Text>
            <Button title="Get Joke" onPress={fetchJoke} />
        </View>
    );
};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#fff',
    },
    header: {
        fontSize: 24,
        marginBottom: 20,
    },
    joke: {
        fontSize: 18,
        textAlign: 'center',
        marginBottom: 20,
    },
});

export default App;const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#fff',
    },
    header: {
        fontSize: 24,
        marginBottom: 20,
    },
    joke: {
        fontSize: 18,
        textAlign: 'center',
        marginBottom: 20,
    },
});

export default App;const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#fff',
    },
    header: {
        fontSize: 24,
        marginBottom: 20,
    },
    joke: {
        fontSize: 18,
        textAlign: 'center',
        marginBottom: 20,
    },
});

export default App;const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#fff',
    },
    header: {
        fontSize: 24,
        marginBottom: 20,
    },
    joke: {
        fontSize: 18,
        textAlign: 'center',
        marginBottom: 20,
    },
});

export default App;