I am working on a todo application in reactjs. I am using object in react state for title and task. The issue is whenever I try to merge old state with new one it does not work.
Please check my code below.
const [todo, setTodo] = useState({ title: "", task: ""});
const setObj = { title: valueOfTile, task: valueOfTask};
setTodo({...todo , ...setObj});
Also how can I iterate through them? This is what I am doing to iterate:
{Object.keys(todo).map((data, i) => (
<div className="main " key={data}>
<div CLASSNAME="first">
<h1>{todo.title}</h1>
</div>
<div className="second">
<p>{todo.task}</p>
</div>
</div>
))}
I am not sure why I am getting two rows for one added title and task. Check image