M
M
MeMoJlor2021-08-25 16:01:03
JavaScript
MeMoJlor, 2021-08-25 16:01:03

Why doesn't checked: !checked work?

The code looks like this:

class App extends Component {
  state = {
    data: [
      {disc: 'Получить пенсию', chekedItem: false, id:'435'},
      {disc: 'dfdfgf', chekedItem: false, id:'545'},
      {disc: 'dfdfgf', chekedItem: false, id:'565'},
      {disc: 'dfdfgf', chekedItem: false, id:'111'},
    ],
  }

  onCheked = (id, e) => {
    if(e.target === e.currentTarget){
      this.setState(({data}) => {
        const idx = data.findIndex(elem => elem.id === id);
        const old = data[idx]
        const newItem = {...old, chekedItem: !chekedItem};
        const before = data.slice(0 ,idx);
        const after = data.slice(idx + 1);
        const newArr = [...before, newItem, ...after];
        return{
          data: newArr
        }
      })
    }
  }
  
  render() {
    return(
      <div className='mainLayer'>
        <div className='todoLayer'>
          <TodoHeader/>
          <TodoForm addItem={this.addItem}/>
          <TodoList post={this.state.data} onCheked={this.onCheked} deleteItem={this.deleteItem}/>
        </div>
      </div>
    )
  }
}

export default App;


Error: checkedItem' is not defined no-undef

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vadim, 2021-08-25
@MeMoJlor

Well, maybe because it is? checkedItem is not defined.
Where is your checkedItem variable?
I guess you meant to writechekedItem: !old.chekedItem

S
Simkav, 2021-08-25
@Simkav

const newItem = {...old, checkedItem: !checkedItem};

Show where you have your checkedItem

R
Rsa97, 2021-08-25
@Rsa97

Why should it work? What is the value of the checkedItem variable at the time the string is executed ? const newItem = {...old, chekedItem: !chekedItem};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question