我需要简单筛选待办事项列表的帮助我已经成功地删除和添加任务,效果很好,但现在我正在尝试筛选添加的任务,我收到了错误消息我完全是初学者,所以请记住这一点谢谢!
TypeError:无法读取未定义的属性“setState”
26 |这个。设置状态({查询:evt.target.value});
import React, {Component} from 'react';
import '../App.css';
import Form from './Form';
import List from './List';
class App extends Component {
state = {
query: '',
inputValue: "",
todos: [
{value: 'Naumiej siÄ Reacta', done: false},
{value: 'Pucuj trzewiki ', done: true},
]
}
handleChange = (evt) => {
this.setState({inputValue: evt.target.value});
}
removeMe = (index) =>{
this.setState({
todos: this.state.todos.filter((_, i) => i !== index)
})
}
searchChanged(evt) {
this.setState({query: evt.target.value});
}
handleSubmit = (evt) => {
evt.preventDefault();
const newTodo = {
value: this.state.inputValue
};
const todos = this.state.todos;
todos.push(newTodo);
this.setState({todos: todos, inputValue: ''})
}
render() {
return (
<div className="App">
<input type="text" placeholder="Search..." onChange=
{this.searchChanged} />
<Form
handleChange={this.handleChange}
inputValue={this.state.inputValue}
handleSubmit={this.handleSubmit}
/>
<List
removeMe={this.removeMe}
todos={this.state.todos}
query={this.state.query}
/>
</div>
);
}
}
export default App;
列表
import React, {Component} from 'react';
import Task from './Task';
class List extends Component {
render() {
let serchedTasks = this.props.todos.filter(
(todos) => {
return todos.value.indexOf(this.props.query) !== -1;
}
);
return (
<div className="List">
{serchedTasks.map((todo, index) => {
return (
<Task
key={index}
index={index}
removeMe={this.props.removeMe}
todo={todo}
/>
)
})}
</div>
)
}
}
export default List;