Skip to content

Commit

Permalink
Tasks Component Part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Oct 25, 2022
1 parent d8499b7 commit 495973f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
31 changes: 24 additions & 7 deletions react-hooks/home/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions react-hooks/home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"uuid": "^3.3.2",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions react-hooks/home/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState } from 'react';
import Joke from './Joke';
import Stories from './Stories';
import Tasks from './Tasks';

function App() {
const [userQuery, setUserQuery] = useState('');
Expand Down Expand Up @@ -35,6 +36,8 @@ function App() {
<hr />
<Joke />
<hr />
<Tasks />
<hr />
<Stories />
</div>
);
Expand Down
39 changes: 39 additions & 0 deletions react-hooks/home/src/Tasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React, { useState } from 'react';
import uuid from 'uuid/v4';

function Tasks() {
const [taskText, setTaskText] = useState('');
const [tasks, setTasks] = useState([]);
const [completedTasks, setCompletedTasks] = useState([]);

const updateTaskText = event => {
setTaskText(event.target.value);
}

const addTask = () => {
setTasks([...tasks, { taskText, id: uuid() }]);
}

console.log('tasks', tasks);

return (
<div>
<h3>Tasks</h3>
<div className='form'>
<input value={taskText} onChange={updateTaskText} />
<button onClick={addTask}>Add Task</button>
</div>
<div className='task-list'>
{
tasks.map(task => {
const { id, taskText } = task;

return <div key={id}>{taskText}</div>
})
}
</div>
</div>
)
}

export default Tasks;

0 comments on commit 495973f

Please sign in to comment.