Skip to content

Instantly share code, notes, and snippets.

@brodeynewman
Last active May 29, 2017 16:00
Show Gist options
  • Select an option

  • Save brodeynewman/41032034712df12b752d97a467f4caac to your computer and use it in GitHub Desktop.

Select an option

Save brodeynewman/41032034712df12b752d97a467f4caac to your computer and use it in GitHub Desktop.
Optimal animation toggling with react.
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