Answer the question
In order to leave comments, you need to log in
Add class?
Good evening.
i can't add class via react setState.
state = {
done: false
};
onLabelClick = () => {
this.setState({
done: true
});
}
let classNames = "todo-list-item";
if (done) {
classNames += " done"
}
.todo-list-item done {
text-decoration: line-through;
}
Answer the question
In order to leave comments, you need to log in
.todo-list-item.done {
text-decoration: line-through;
}
state = {
done: false,
};
onLabelClick = () => {
this.setState({
done: true
});
};
render() {
return (
<div className={'todo-list-item' + (this.state.done ? ' done' : '')} onClick={this.onLabelClick}>text</div>
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question