-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
42 lines (36 loc) · 1023 Bytes
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Imports
import React, {useState} from 'react';
import {View, Text, Button, StyleSheet} from 'react-native';
import {Affirmations} from './Affirmation';
const App = () => {
// Test affirmations
const affirmations: string[] = Affirmations;
// State
const [currentAffirmation, setCurrentAffirmation] = useState<string>('');
// Function to fetch a new affirmation
const getNewAffirmation = (): void => {
const randomIndex = Math.floor(Math.random() * affirmations.length);
setCurrentAffirmation(affirmations[randomIndex]);
};
return (
<View style={styles.container}>
<Text style={styles.affirmationText}>{currentAffirmation}</Text>
<Button title="New Affirmation" onPress={getNewAffirmation} />
</View>
);
};
// Styles
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
affirmationText: {
fontSize: 24,
marginBottom: 20,
},
});
// Export
export default App;