Skip to main content
3 de 3
Mejora de formato
user avatar
user avatar

"Error: Maximum update depth exceeded"

Estoy creando una "Lista de tareas" pero me sale este error:

"Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops"

Este es mi código:

import React from 'react';
import './App.css';

import List from './Components/List';
import TaskForm from './Components/TaskForm';

import TaskList from './Sample/TaskList.json'
class App extends React.Component{
  
  state = {
    taskLists: TaskList
  }
  
  addTask = (title,description) => {
    const newTask = {
      title: title,
      description: description,
      id: this.state.taskLists.length
    }
    this.setState({
      taskLists : [...this.state.taskLists, newTask]
    })
  }

  render(){
    return(
      <div>
        <TaskForm addTask={this.addTask} />
        <List tasks={this.state.taskLists} />
      </div>
    );
  }
}

export default App; 

Apareció cuando agregué esta parte de código:

this.setState({
      taskLists : [...this.state.taskLists, newTask]
    })
Diego
  • 5
  • 1
  • 4