Skip to content

Instantly share code, notes, and snippets.

@DZuz14
Last active October 4, 2021 19:13
Show Gist options
  • Save DZuz14/d75100bb7dba0d6f88628d7ca0f7ad26 to your computer and use it in GitHub Desktop.
Save DZuz14/d75100bb7dba0d6f88628d7ca0f7ad26 to your computer and use it in GitHub Desktop.
Slider With React Hooks 7
/** @jsx jsx */
import React, { useState, useEffect, useRef } from 'react'
import { css, jsx } from '@emotion/core'
import SliderContent from './SliderContent'
import Slide from './Slide'
/**
* @function Slider
*/
const Slider = props => {
const getWidth = () => window.innerWidth
const [state, setState] = useState({
translate: 0,
transition: 0.45
})
const { translate, transition } = state
return (
<div css={SliderCSS}>
<SliderContent
translate={translate}
transition={transition}
width={getWidth() * props.slides.length}
>
{props.slides.map((slide, i) => (
<Slide key={slide + i} content={slide} />
))}
</SliderContent>
</div>
)
}
const SliderCSS = css`
position: relative;
height: 100vh;
width: 100vw;
margin: 0 auto;
overflow: hidden;
`
export default Slider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment