Skip to content

Instantly share code, notes, and snippets.

@RoyalHunt
Created September 11, 2017 07:32
Show Gist options
  • Save RoyalHunt/a9deeab6c6ee4c157f7a531798bafa07 to your computer and use it in GitHub Desktop.
Save RoyalHunt/a9deeab6c6ee4c157f7a531798bafa07 to your computer and use it in GitHub Desktop.
componentDidMount() {
this.updateDimensions()
window.addEventListener('resize', this.updateDimensions)
}
componentWillUnmount() {
window.removeEventListener('resize', this.updateDimensions)
}
updateDimensions = () => {
if (window.innerWidth > 1700) {
this.setState({ slideToShow: 7 })
} else if (window.innerWidth > 1500) {
this.setState({ slideToShow: 6 })
} else if (window.innerWidth > 1350) {
this.setState({ slideToShow: 5 })
} else if (window.innerWidth > 1180) {
this.setState({ slideToShow: 4 })
} else if (window.innerWidth > 1026) {
this.setState({ slideToShow: 3 })
} else if (window.innerWidth > 950) {
this.setState({ slideToShow: 4 })
} else if (window.innerWidth > 730) {
this.setState({ slideToShow: 3 })
} else if (window.innerWidth > 570) {
this.setState({ slideToShow: 2 })
} else {
this.setState({ slideToShow: 1 })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment