Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ const App = () => {
const [todos, setTodos] = useState(todosData);

// get the newTodo from NewTodo.js here inside this function
const handleAddTodo = () => {};
const handleAddTodo = (newTodo) => {
console.log(newTodo);
setTodos([...todos, newTodo]);
};

return (
<div>
<NewTodo />
<Todos />
<div className='container'>
<NewTodo addTodo={handleAddTodo}/>
<Todos todos={todos} />
</div>
);
};
Expand Down
12 changes: 8 additions & 4 deletions src/components/NewTodo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import PropTypes from 'prop-types';
import { v4 as uuidv4 } from 'uuid';

const NewTodo = (props) => {
const [todo, setTodo] = useState();
const [todo, setTodo] = useState({title: '', desc: ''});

// for handling todo state changes
const handleChange = (e) => {};

const handleChange = (e) => {
setTodo({...todo, [e.target.name]:e.target.value});
};
// submit the form and send newTodo in App.js
const handleSubmit = (e) => {
e.preventDefault();
const newTodo = {
id: uuidv4()
id: uuidv4(),
title: todo.title,
desc: todo.desc
};
props.addTodo(newTodo);

// for reset todo state
setTodo({
Expand Down