-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
47 lines (38 loc) · 1.03 KB
/
App.js
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
43
44
45
46
47
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
// components
import Home from './components/Home';
//styled components
import { Container } from './styles/appStyles';
// Async Storage
import AsyncStorage from '@react-native-async-storage/async-storage';
import AppLoading from 'expo-app-loading';
export default function App() {
const [ready, setReady] = useState(false);
// initial todos
const initialTodos = [];
const [todos, setTodos] = useState(initialTodos);
const loadTodos = async () => {
try {
const data = await AsyncStorage.getItem('storedTodos');
return data != null ? setTodos(JSON.parse(data)) : null;
} catch (error) {
console.log(error);
}
};
if (!ready) {
return (
<AppLoading
startAsync={loadTodos}
onFinish={() => setReady(true)}
onError={console.warn}
/>
);
}
return (
<Container>
<StatusBar style='light' />
<Home todos={todos} setTodos={setTodos} />
</Container>
);
}