lundi 18 février 2019

React - check all

Problem

I don't understand how to check all the boxes, Before ask something i saw different posts:

first stackOverflow post

second stackOverflow post

so far i tried to implement a little function but it doesn't work

this is my first part of my class App

class App extends React.Component{
  constructor(props) {
      super(props)
      this.state = {
          todoValue: "",
          filterType: "All",
          todos: [],
      }
  }

checkAll = () => {
    this.setState((prevState) => {
        return {
            todos: prevState.todos.map((item, i) => {
                    return {
                        ...item,
                        done: !prevState.todos[i].done,
                    }
            })
        }
    })
}

this is the render method

render() {
      return (
          <div className="container">
                <Header countTodo={this.state.todos.length}/>
                <Form handleDelete={this.handleDelete} 
                    handleToggle={this.handleToggle}
                    handleClick={this.handleClick} 
                    handleChange={this.handleChange} 
                    todoValue={this.state.todoValue} 
                    todos={this.getVisibleTodos()}/>
                    <input type="checkbox" onClick={this.checkAll}></input>
                <Footer setActiveFilter={this.setActiveFilter} 
                    deleteCompleted={this.deleteCompleted} 
                    filter={this.state.filterType  && "New"}/>

          </div>
      )
  }
}




Aucun commentaire:

Enregistrer un commentaire