React
by ronnjoe
HTML
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
.done {
color: rgba(0, 0, 0, 0.3);
text-decoration: line-through;
}
input {
margin-right: 5px;
}
React
class TodoApp extends React.Component {
constructor (){
super()
this.state = {
listofItems : [{
id:1,
name:"addidas",
vote:0
},{
id:2,
name:"Nike",
vote:0
},{
id:3,
name:"Puma",
vote:0
}]
}
this.handleClick = this.handleClick.bind(this)
}
handleClick(id){
console.log(id);
}
render(){
return (
<div>
{
this.state.listofItems.map(item=><div key={item.id}> <h1>{item.name}</h1><h2>{item.vote}</h2> <button onChange={this.handleClick(item.id)}>Plus</button><button onClick={this.handleClick()}>Minus</button></div>
)}
</div>
)
}
}
ReactDOM.render(<TodoApp />, document.querySelector("#app"))