akiran / akiran/react-slick

Proper way of handling multiple sliders inside a map function

Open
#1,998 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11.9k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

Tried adding buttons on each slider, but the only slider working is the last one.

```
import React, { useRef } from "react"
import PropTypes from "prop-types"
//import BackgroundImage from "gatsby-background-image"
import GatsbyImage from "gatsby-image"
import { SRLWrapper } from "simple-react-lightbox"
import Slider from "react-slick"
import { CgArrowLeft, CgArrowRight } from "react-icons/cg"

const options = {
settings: {
usePreact: true,
autoplaySpeed: 0,
},
thumbnails: {
showThumbnails: false,
},
}

const EachDivision = ({ nodes }) => {
const sourceSlider = useRef()
const next = () => {
sourceSlider.current.slickNext()
}
const prev = () => {
sourceSlider.current.slickPrev()
}

const settings = {
arrows: false,
dots: false,
infinite: true,
slidesToShow: 1,
slidesToScroll: 1,
draggable: false,
autoplay: false,
responsive: [
{
breakpoint: 1024,
},
{
breakpoint: 10000, // a unrealistically big number to cover up greatest screen resolution
settings: "unslick",
},
],
}

const sorted = nodes.nodes
.filter(item => item.id !== "cG9zdDozODA=")
.concat(nodes.nodes.filter(item => item.id === "cG9zdDozODA="))

return (

{sorted.map(node => {
return (




{node.title}



{node.divisionFields.images && (




{console.log(node.slug.replace(/-/g, "_"))}
{node.divisionFields.images.map(image => {
return (





{image.imageTitle}



)
})}












)}

{node.divisionFields.showButton && (

{node.divisionFields.buttonText}

)}


)
})}

)
}

EachDivision.propTypes = {
nodes: PropTypes.object.isRequired,
}

export default EachDivision

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.