我目前正在创建一个 React todo 应用程序。所以基本上我有两个组件 TodoList 和 TodoItem
TodoList 组件将接收一个包含 title 作为属性的对象数组,并通过 TodoItem 组件映射到它
在我的 TodoItem 组件中,用户可以选择编辑或删除项目。如果用户选择编辑,则会使用文本区域显示带有现有标题的模式。但是,我在实现这个函数时遇到了麻烦,因为模态总是与数组的最后一个元素一起显示。
import React, { Component } from 'react'
import TodoItem from './TodoItem'
import { connect } from 'react-redux'
import { clear_todo } from '../store/actions/todoActions'
class Todolist extends Component {
clearList = (e) => {
e.preventDefault()
this.props.clearList(clear_todo());
}
handleChange = (index, title) => {
this.setState({
[index]: title
})
}
render() {
const { items, editItem } = this.props.todo
return (
<ul className="list-group my-5">
<h3 …Run Code Online (Sandbox Code Playgroud)