Answer the question
In order to leave comments, you need to log in
Where are the errors in the code?
class MyComponent extends React.component {
constructor() {
this.state = {
counter: 0,
items: [1, 2]
};
}
increase(this) {
this.state.counter++;
}
addItem() {
this.state.items = this.state.items.push(this.state.items.length+1);
}
render() {
<div class="data">
<div>{this.state.counter}</div>
<ul>
{this.state.items.map(item => (
<li key={item}>element {item}</li>
))}
</ul>
</div>
<div class="actions">
<button type="button" onclick={this.increase}>zwiększ</button>
<button type="button" onclick={this.addItem}>dodaj</button>
</div>
}
}
ReactDOM.render(<MyComponent>, document.querySelector("body"));
Answer the question
In order to leave comments, you need to log in
here:
constructor() {
this.state = {
counter: 0,
items: [1, 2]
};
}
increase(this) {
this.state.counter++;
}
addItem() {
this.state.items = this.state.items.push(this.state.items.length+1);
}
super(props);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question