question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Focused index is not persisted when carousel component is re-rendered

See original GitHub issue

Describe the bug Focused index of carousel is not persisted when carousel component is re-rendered.

To Reproduce Steps to reproduce the behavior:

  1. Render Carousel component with some data
  2. Swipe to the second item of carousel
  3. Rerender Carousel component(in my case it’s update of the data in react-query hook, but could be any reason)
  4. Focused item is reset to the first one

Expected behavior Focused item should be second item, so the focused item state should persist across the component re-renders, otherwise it’s impossible to update the data, that being rendered by component

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dohooocommented, May 12, 2022

Uhhhh… You are right. I did some thing wrong with #178. I will fixed it ASAP.

1reaction
todoronecommented, May 12, 2022

This is the logic I just changed, so if the data changes, it resets to the first one.

What is the rationale behind such behaviour? I have never experienced it in other carousel packages, focused state is persisted no matter how many re-renders occurred. And this logic may not be compatible with React 18 and concurrent rendering mode where rendering can be stopped/continued at any moment of time.

We can’t use useRef / useState for every use-case. For me it’s: const { data } = useQuery(...) and it could be updated any time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React multi carousel renders items wrongly - Stack Overflow
actually this carousel makes a <li> for each element to manoeuvre the carousel effects as you can see in the inspect screenshot.
Read more >
ngx-owl-carousel-o - npm
Import CarouselModule into a module which declares a component intended to have a carousel. import { CarouselModule } from 'ngx-owl-carousel-o'; ...
Read more >
Building a Smooth Image Carousel with FlatList in React Native
Below, I'm going to show you how to build an image carousel with React Native's <FlatList /> core component. Users will be able...
Read more >
lightning-datatable - documentation - Salesforce Developers
This component implements styling from the data tables blueprint in the Salesforce Lightning Design System. lightning-datatable is not supported on mobile ...
Read more >
Before After LWC Slider - Salesforce Stack Exchange
Note that I query the component every time not because it is necessary ... and it gets re-rendered somehow, the code might stop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found