|
Created by Akaki Khotcholava
over 6 years ago
|
|
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;
There are no comments, be the first and leave one below:
Want to create your own Notes for free with GoConqr? Learn more.