REACT - toggle class onclick

后端 未结 14 1936
长情又很酷
长情又很酷 2020-11-27 11:40

I am trying to figure out how to toggle an active class onClick to change CSS properties.

I have taken many approaches, and read many SO answers. Using

14条回答
  •  情歌与酒
    2020-11-27 12:01

    using React you can add toggle class to any id/element, try

    style.css

    .hide-text{
        display: none !important;
        /* transition: 2s all ease-in 0.9s; */
      }
    .left-menu-main-link{
        transition: all ease-in 0.4s;
    }
    .leftbar-open{
        width: 240px;
        min-width: 240px;
        /* transition: all ease-in 0.4s; */
    }
    .leftbar-close{
        width: 88px;
        min-width:88px;
        transition: all ease-in 0.4s;
    }
    

    fileName.js

    ......
        ToggleMenu=()=>{
                 this.setState({
                    isActive: !this.state.isActive
                  })
                  console.log(this.state.isActive)
            }
            render() {
                return (
                    
    Welcome!
    Welcome
    SDO Rizwan
    ) } ......

提交回复
热议问题