-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTodoList.tsx
More file actions
49 lines (44 loc) · 1.36 KB
/
TodoList.tsx
File metadata and controls
49 lines (44 loc) · 1.36 KB
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
import React, { useState } from 'react';
import { View, Text } from 'react-native';
import { Container, Card, Input } from '../../components/StyledComponents';
import styled from 'styled-components/native';
import { Button } from '../../components/Button';
import { useSelector, useDispatch } from 'react-redux';
import { todoListSelector } from '../../modules/todos/selectors';
import { TodoActions } from '../../modules/todos/actions';
import { wording } from '../../utils/wording';
export const TodoList = () => {
const todos = useSelector(todoListSelector);
const dispatch = useDispatch();
const [textTodo, setTextTodo] = useState('');
const onChangeText = (text: string) => setTextTodo(text);
const onSubmitTodo = () => {
dispatch(TodoActions.addTodo(textTodo));
setTextTodo('');
};
return (
<Container>
<Card>
<StyledInput
value={textTodo}
onChangeText={onChangeText}
placeholder={wording.todos.newTodo}
/>
<Button title={wording.todos.add} onPress={onSubmitTodo} />
<TodosContainer>
{todos.map((todo, index) => (
<Text key={index}>{todo}</Text>
))}
</TodosContainer>
</Card>
</Container>
);
};
const TodosContainer = styled(View)`
text-align: left;
margin-top: 8;
`;
const StyledInput = styled(Input)`
width: 100%;
margin: 8px;
`;