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
13 changes: 9 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import React, { useState } from 'react';
import { v4 as uuidv4 } from 'uuid';

Expand All @@ -21,12 +22,16 @@ const App = () => {
const [todos, setTodos] = useState(todosData);

// get the newTodo from NewTodo.js here inside this function
const handleAddTodo = () => {};

const handleAddTodo = (newTodo) => {
setTodos((oldTodo)=>{
const newTodos=[...oldTodo, (newTodo)]
return newTodos
})
};
return (
<div>
<NewTodo />
<Todos />
<NewTodo getTodo={handleAddTodo} />
<Todos todos={todos} />
</div>
);
};
Expand Down
24 changes: 17 additions & 7 deletions src/components/NewTodo.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
/* eslint-disable */
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { v4 as uuidv4 } from 'uuid';

const NewTodo = (props) => {
const [todo, setTodo] = useState();

const [todo, setTodo] = useState({ title: '', desc: '' });
const { title, desc } = todo;
// for handling todo state changes
const handleChange = (e) => {};
const handleChange = (e) => {
const name = e.target.name;
const value = e.target.value;
setTodo({
...todo,
[name]: value
});
};

// submit the form and send newTodo in App.js
const handleSubmit = (e) => {
e.preventDefault();
const newTodo = {
id: uuidv4()
id: uuidv4(),
title: title,
desc: desc
};

props.getTodo(newTodo);
// for reset todo state
setTodo({
title: '',
Expand All @@ -33,7 +43,7 @@ const NewTodo = (props) => {
type="text"
name="title"
id="title"
value={todo.title}
value={title}
onChange={handleChange}
required
/>
Expand All @@ -44,7 +54,7 @@ const NewTodo = (props) => {
<textarea
name="desc"
id="desc"
value={todo.desc}
value={desc}
onChange={handleChange}
required></textarea>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Todo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable */
import React from 'react';
import PropTypes from 'prop-types';

const Todo = (props) => {
const { title, desc } = props.todo;
const { title, desc } = props.todo;
return (
<article className="todo">
<h3 className="todo__title">{title}</h3>
Expand Down
1 change: 1 addition & 0 deletions src/components/Todos.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import React from 'react';
import PropTypes from 'prop-types';

Expand Down
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ textarea {
border-radius: 0.6rem;
width: 25rem;
max-width: 100%;
margin: 0 auto;
}

form {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
Expand Down