-
-
Save theolampert/8fce379d1908332775d7 to your computer and use it in GitHub Desktop.
Flickity React integration
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 from 'react'; | |
import Flickity from 'flickity'; | |
export default React.createClass({ | |
getInitialState() { | |
return { | |
selectedIndex: 0 | |
} | |
}, | |
componentDidMount() { | |
const carousel = this.refs.carousel; | |
this.flkty = new Flickity(carousel, this.props.options); | |
this.flkty.on('cellSelect', this.updateSelected); | |
}, | |
updateSelected() { | |
var index = this.flkty.selectedIndex; | |
this.setState({ | |
selectedIndex: index | |
}); | |
}, | |
componentWillUnmount() { | |
if (this.flkty) { | |
this.flkty.off('cellSelect', this.updateSelected); | |
this.flkty.destroy(); | |
} | |
}, | |
render() { | |
return ( | |
<div ref='carousel' className='carousel'> | |
{this.props.children} | |
</div> | |
); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment