-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
77 lines (66 loc) · 1.91 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { useEffect, useRef, useState } from "react";
import { Provider } from "react-redux";
import { StyleSheet, View } from "react-native";
import update from "immutability-helper";
import { Button, Header, Input } from "react-native-elements";
import store from "./store";
import List from "./components/List";
const App = () => {
const inputRef = useRef();
const [value, setValue] = useState("");
const [listToDos, setListToDos] = useState([]);
const color = "#009999";
const add = () => {
if (value !== "") {
setListToDos([value, ...listToDos]);
setValue("");
}
};
const deleteToDo = (id) => {
setListToDos(update(listToDos, { $splice: [[id, 1]] }));
};
useEffect(() => {
console.log(listToDos);
}, [listToDos]);
return (
<Provider store={store}>
<View style={styles.container}>
<Header
backgroundColor={color}
leftComponent={{ icon: "menu", color: "#fff" }}
centerComponent={{
text: "Моё первое приложение",
style: { color: "#fff" },
}}
rightComponent={{ icon: "home", color: "#fff" }}
/>
<Input
inputStyle={{ marginTop: 5 }}
ref={inputRef}
placeholder="Введите задание"
value={value}
onChangeText={(value) => setValue(value)}
onSubmitEditing={add}
/>
<View style={{ alignItems: "center", padding: 0 }}>
<Button
title="Отправить"
onPress={add}
buttonStyle={{
width: "100%",
backgroundColor: color,
}}
/>
</View>
<List listToDos={listToDos} color={color} deleteToDo={deleteToDo} />
</View>
</Provider>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: "#fff",
color: "#000",
},
});
export default App;