Reset slider position on every render of carousel
See original GitHub issue#18 hey, I am facing an issue with react-responsive-carousel.
I have a parent component :
//Main
return (
<>
<Wrapper>
<UserDisplay
user={currentUserDisplay}
handleLike={handleLike}
handleUnLike={handleUnLike}
/>
</Wrapper>
</>
);
and a child component: //UserDisplay
const UserDisplay = ({ user, handleLike, handleUnLike }) => {
const { firstName, images } = user;
<div>
<Carousel
infiniteLoop={true}
showStatus={false}
showArrows={false}
showThumbs={false}
selectedItem={0}
>
{images.map(({ img }, i) => (
<div className="item" key={i}>
<ProfilePicture urlPath={img}>
<Text>{`${firstName}`}</Text>
</ProfilePicture>
</div>
))}
</Carousel>
</div>
};
Whenever a user changes at parent component , different images will be displayed at the carousel, as expected. My problem is , the slider’s position from previous user remains the same for the next carousel. The selectedItem property assigns 0 only for the first render .
for example: if I was starting from position 0 , then scrolling to the third image at the first user , i will also view the third image of the next user, when the current user changes.
what I try to achieve is , resetting the slider’s position to 0 whenever a user changes. thanks 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to reset the position of the carousel when the button was ...
I'm trying to make the image slider to reset its position when the "Main Hall" to "Parking Space" buttons were clicked.
Read more >React - How To Reset The Value Of Many Sliders At Once
goTo(slideNumber, dontAnimate), Go to slide index, if dontAnimatetrue, it happens without animation. next(), Change current slide to next slide. prev(), Change.
Read more >JavaScript - Bootstrap
Use data attributes to easily control the position of the carousel. data-slide accepts the keywords prev or next , which alters the slide...
Read more >Documentation - Keen-Slider
Documentation. Complete documentation of the installation and usage of Keen-Slider. For the documentation of the old version click here.
Read more >Carousel | Components - BootstrapVue
When using images in each slide, ensure they all have the same dimensions (or ... Internally, <b-carousel-slide> uses the <b-img> component to render...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
A better workaround to your problem is to use the
key
prop since it creates a new instance rather than update the current one when thekey
changes. Your code will be something like this:I had the same problem with react-responsive-carousel days ago, I just did this:
I will use your component as example:
I hope this could help you 👍