Created
December 8, 2018 09:19
-
-
Save inPhoenix/bc2c52ddedd7ce50dab3fcc6ab268956 to your computer and use it in GitHub Desktop.
React Spring super simple example
This file contains 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' | |
import { Spring } from 'react-spring' | |
class ShowHide extends Component { | |
state = { | |
opacity: 0 | |
} | |
onHover = () => { | |
this.setState(prevState => ({ | |
opacity: prevState.opacity === 0 ? 1 : 0 | |
})) | |
} | |
render() { | |
return ( | |
<Spring from={{ opacity: 0 }} to={{ opacity: this.state.opacity }}> | |
{props => ( | |
<div style={props} onClick={this.onHover}> | |
Hide Me! | |
</div> | |
)} | |
</Spring> | |
) | |
} | |
} | |
export default ShowHide |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment