React Slick 有很好的例子来说明如何让它运行,然而这个是在类组件中,任何关于如何在使其成为功能组件时修复它的想法
https://react-slick.neostack.com/docs/example/as-nav-for
import React from "react";
import Slider from "react-slick";
export default function SyncSlider() {
const [nav1, setNav1] = React.useState(null)
const [nav2, setNav2] = React.useState(null)
let slider1 = []
let slider2 = []
React.useEffect(() => {
setNav1(slider1)
setNav2(slider2)
}, [slider1, slider2])
return (
<div>
<h2>Slider Syncing (AsNavFor)</h2>
<h4>First Slider</h4>
<Slider
asNavFor={nav1}
ref={slider => (slider1 = slider)}
>
<div>
<h3>1</h3>
</div>
<div>
<h3>2</h3>
</div>
<div>
<h3>3</h3>
</div>
<div>
<h3>4</h3>
</div>
<div>
<h3>5</h3>
</div>
<div>
<h3>6</h3>
</div>
</Slider>
<h4>Second Slider</h4>
<Slider
asNavFor={nav2}
ref={slider => (slider2 = slider)}
slidesToShow={3}
swipeToSlide={true}
focusOnSelect={true}
>
<div>
<h3>1</h3>
</div>
<div>
<h3>2</h3>
</div>
<div>
<h3>3</h3>
</div>
<div>
<h3>4</h3>
</div>
<div>
<h3>5</h3>
</div>
<div>
<h3>6</h3>
</div>
</Slider>
</div>
);
}
问题看起来像在这里:
let slider1 = []
let slider2 = []
滑块显示但不同步,有什么想法、输入、解决方案让这个工作?