1
import {deleteTodo} from "../actions/todos";
@connect(store => {
return {
todos: store.todos.todos,
}
})
class ViewTodo extends React.Component{
handleDelete(id){
this.props.history.goBack();
//even if the deleteTodo() method is after the goBack(), it still throws error
this.props.dispatch(deleteTodo(id));
}
render(){
const todo = this.props.todos.filter(e => parseInt(this.props.match.params.id) === e.id)[0];
return (
<div>
<TodoDeleteButton
onDelete={() => this.handleDelete(todo.id)}
/>
<h2>{todo.title}</h2>
Lorsque l'élément courant de todo est supprimé, réagissez tente de rendre la nouvelle {todo.title}
mais l'élément todo manque et génère une erreur. Y-a-t-il un moyen d'éviter ça ?React article indéfini après Redux supprimer