Notes
Untitled
Content of the notes (1)
Page 1
import React, { Component } from 'react';
class Counter extends Component {
state = {
count: 1,
imgUrl: 'https://picsum.photos/200',
defaultText: 'Image title'
};
render () {
let classes = "badge m-2 badge-";
classes += this.state.count === 0 ? "warning" : "primary";
return(
<React.Fragment>
<div>
<img src={this.state.imgUrl} alt={this.state.defaultText}/>
<span style={this.styles} className={classes}>{this.formatCount()}</span>
<button onClick={this.formatCount()}>Increment</button>
</div>
</React.Fragment>
)
}
formatCount() {
const {count} = this.state;
return count === 0 ? "Zero" : count;
}
}
export default Counter;
Information
- Description
- Note on Untitled, created by Akaki Khotcholava on 12/12/2018.
- Created by
- Akaki Khotcholava
- Views
- 23
- Tags
- Rating