I am trying to make a Todo app using React.js.
I took todo data from an in-app js file as a JSON object. I want to add more todo in my list which I want to store in that js file as a JSON object.
I want to append another JSON object with existing. How can I do it?
TodoList.js file
const TodoList=
[
{
"id": 1,
"title": "Learn backbone",
"complete": false,
"canceled": false,
"date": new Date().getTime()
},
{
"id": 2,
"title": "Go for a run",
"complete": false,
"canceled": false,
"date": new Date().getTime()
}
]
export default TodoList;
New TodoList.js file should be like this:
const TodoList=
[
{
"id": 1,
"title": "Learn backbone",
"complete": false,
"canceled": false,
"date": new Date().getTime()
},
{
"id": 2,
"title": "Go for a run",
"complete": false,
"canceled": false,
"date": new Date().getTime()
},
{
"id": 3,
"title": "Have Lunch",
"complete": true,
"canceled": false,
"date": new Date().getTime()
}
]
export default TodoList
TodoListconst is an array. You can either use spread operator or useTodoList.push(newTodo). This is more of a Javascript question than a react tho.