Skip to main content

As Nav For

Slider Syncing (AsNavFor)

First Slider

1

Second Slider

1

2

3

import React, { useState, useEffect, useRef } from "react";
import Slider from "react-slick";

function AsNavFor() {
const [nav1, setNav1] = useState(null);
const [nav2, setNav2] = useState(null);
let sliderRef1 = useRef(null);
let sliderRef2 = useRef(null);

useEffect(() => {
setNav1(sliderRef1);
setNav2(sliderRef2);
}, []);
return (
<div className="slider-container">
<h2>Slider Syncing (AsNavFor)</h2>
<h4>First Slider</h4>
<Slider asNavFor={nav2} ref={slider => (sliderRef1 = 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={nav1}
ref={slider => (sliderRef2 = 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>
);
}

export default AsNavFor;