ReactJS: Hover over button

This entry is part 35 of 35 in the series React JS

See the Pen React hover demo by Smashcat (@naturalclar) on CodePen.

class Icon extends React.Component{
  constructor (props) {
    super(props);
    this.state= {
      hover: false
    };
  }
  
   handleHover() {
    this.setState({hover: !this.state.hover});
  }
  
  render() {
    var iconStyle={
      transform: this.state.hover ? 'translateY(-5px)' : 'none',
      boxShadow: this.state.hover ? '3px 3px 5px #000' : 'none',
      color: this.state.hover? "#fff" : "#aaa",
      background: this.state.hover? '#55acee' :'#222',
      transition: "all .3s",
      borderRadius: '50%',
      height: 50,
      width: 50,
      textAlign:'center',
      lineHeight: '50px'
    }
    return (
      <a href={this.props.href}><i className={this.props.icon} style={iconStyle} onMouseEnter={()=>this.handleHover()} onMouseLeave={()=>this.handleHover()}></i></a>
    )
  };
  
}

class App extends React.Component {
  render() {
    return (
      <Icon href="#" icon="fa fa-2x fa-twitter" />
    )
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);
Series Navigation<< React: Button Dropdown
ReactJS: A simple react component >>