美文网首页
React 组件传对象

React 组件传对象

作者: _嘿嘿_ | 来源:发表于2018-06-08 16:57 被阅读0次

    <LikeButton wordings={{likedText: '已赞', unlikedText: '赞'}} />

    class LikeButton extends Component {
    constructor () {
    super()
    this.state = { isLiked: false }
    }

    handleClickOnLikeButton () {
    this.setState({
    isLiked: !this.state.isLiked
    })
    }

    render () {
    const wordings = this.props.wordings || {
    likedText: '取消',
    unlikedText: '点赞'
    }
    return (
    <button onClick={this.handleClickOnLikeButton.bind(this)}>
    {this.state.isLiked ? wordings.likedText : wordings.unlikedText} 👍
    </button>
    )
    }
    }

    相关文章

      网友评论

          本文标题:React 组件传对象

          本文链接:https://www.haomeiwen.com/subject/qwvasftx.html