Last active
May 29, 2017 16:00
-
-
Save brodeynewman/41032034712df12b752d97a467f4caac to your computer and use it in GitHub Desktop.
Optimal animation toggling with react.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| class Toggle extends Component { | |
| constructor() { | |
| super() | |
| this.state = { | |
| collapsed: true | |
| }; | |
| } | |
| toggleAnimation() { | |
| const collapsed = !this.state.collapsed; | |
| this.setState( { collapsed } ); | |
| } | |
| render() { | |
| const { collapsed } = this.state; | |
| const navClass = collapsed ? ‘collapse’ : ‘’; | |
| return ( | |
| <button onClick={this.toggleAnimation.bind(this)}></button> | |
| <nav class=“nav ” + navClass> | |
| <ul> | |
| <li /> | |
| <li /> | |
| <li /> | |
| </ul> | |
| </nav> | |
| ); | |
| } | |
| } | |
| export default Toggle; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment