akiran / akiran/react-slick

Proper way of handling multiple sliders inside a map function

未关闭
#1,998 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
11.9k
派生
2.1k
PR 合并指标
30 天内没有已合并 PR

描述

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

```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。