Answer the question
In order to leave comments, you need to log in
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;
Answer the question
In order to leave comments, you need to log in
Well, maybe because it is? checkedItem is not defined.
Where is your checkedItem variable?
I guess you meant to writechekedItem: !old.chekedItem
const newItem = {...old, checkedItem: !checkedItem};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question