How to add a CSS class to an element on click - React

前端 未结 4 1949
既然无缘
既然无缘 2021-01-03 01:46

How do you add a CSS class to an existing REACT element on click?

I have a JSFiddle created: https://jsfiddle.net/5r25psub/

In the fiddle, the code only wor

4条回答
  •  太阳男子
    2021-01-03 02:39

    You can use the module classnames found here:

    https://www.npmjs.com/package/classnames

    So you would do something like:

    getClassNames() {
        return classNames({
            'blue':  this.state.clicked,
            'green':  !this.state.clicked
        });
    },
    render () {
        return 

提交回复
热议问题