创建组件Like.js
一开始设置为黑色false,isLiked如果为true渲染红心,false渲染黑心
setState时用了两种方法
import React, { Component } from 'react'
export default class Like extends Component {
constructor(){
super()
this.state={
isLiked:false
}
}
render() {
return (
<span onClick={this.handleLike.bind(this)}>
{
this.state.isLiked ? '取消 标签:prevState,一个点,isLiked,console,react,state,按钮,false,setState From: https://blog.51cto.com/u_12422954/5985782