More perf changes

This commit is contained in:
Bel Curcio
2021-06-08 11:48:55 -03:00
parent 7ef0e2273e
commit dfbca746b2
5 changed files with 66 additions and 49 deletions

View File

@@ -10,7 +10,7 @@ import React, {
import cn from 'classnames'
import { a } from '@react-spring/web'
import s from './ProductSlider.module.css'
import { ArrowLeft, ArrowRight } from '@components/icons'
import ProductSliderControl from '../ProductSliderControl'
const ProductSlider: FC = ({ children }) => {
const [currentSlide, setCurrentSlide] = useState(0)
@@ -73,30 +73,16 @@ const ProductSlider: FC = ({ children }) => {
}
}, [])
const onPrev = React.useCallback(() => slider.prev(), [slider])
const onNext = React.useCallback(() => slider.next(), [slider])
return (
<div className={s.root} ref={sliderContainerRef}>
<div
ref={ref}
className={cn(s.slider, { [s.show]: isMounted }, 'keen-slider')}
>
{slider && (
<div className={s.control}>
<button
className={cn(s.leftControl)}
onClick={slider.prev}
aria-label="Previous Product Image"
>
<ArrowLeft />
</button>
<button
className={cn(s.rightControl)}
onClick={slider.next}
aria-label="Next Product Image"
>
<ArrowRight />
</button>
</div>
)}
{slider && <ProductSliderControl onPrev={onPrev} onNext={onNext} />}
{Children.map(children, (child) => {
// Add the keen-slider__slide className to children
if (isValidElement(child)) {