[英]How can I edit my todo items in React using hooks?
Here is my codesandbox showing the app https://codesandbox.io/s/vibrant-ptolemy-i8f74?file=/src/TodoList.js这是我的代码和框显示应用程序https://codesandbox.io/s/vibrant-ptolemy-i8f74?file=/src/TodoList.js
Right now the code allows me to add, cross out, and delete a todo item, but I want to be able to edit the todos as well.现在,代码允许我添加、划掉和删除待办事项,但我也希望能够编辑待办事项。
I'm not too sure how I would go about it?我不太确定我会怎么做?
This is the current todo item code这是当前的待办事项代码
const Todo = ({ todos, completeTodo, removeTodo }) => {
return todos.map(todo => (
<div className='todo-row'>
<div
key={todo.id}
className={todo.isComplete ? 'complete' : ''}
onClick={() => completeTodo(todo.id)}
>
{todo.text}
</div>
<FaWindowClose onClick={() => removeTodo(todo.id)} />
</div>
));
};
将待办事项文本放入输入中,并使用 todo.id 将其绑定到具有 onChange 的数据模型
https://codesandbox.io/s/interesting-browser-25ciw?file=/src/Todo.js https://codesandbox.io/s/interesting-browser-25ciw?file=/src/Todo.js
updateTodo
function in TodoList.js
TodoList.js
添加updateTodo
函数props.edit
in TodoForm.js
props.edit
中添加TodoForm.js
edit
state in Todo.js
and change to TodoForm
component if edit.id
has valueTodo.js
创建edit
状态并在edit.id
有值时更改为TodoForm
组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.