Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing index does not always switch to that index in render #548

Open
1 task done
JacobFischer opened this issue Oct 4, 2019 · 1 comment
Open
1 task done

Comments

@JacobFischer
Copy link

Setting the index prop to the previous value does not switch rendered index. Upon re-renders of the SwipeableViews component, if the previous render's index value is the same, nothing happens. Even if the user interacted with the component between renders and thus the index has changed.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Updating the index prop on a re-renders of SwipeableViews should always change the view to that slide.

Current Behavior

The view only changes to the specific index based on previous index values. Sometimes different values do not cause a slide change when it should.

Steps to Reproduce (for bugs)

Demo: https://codesandbox.io/s/material-demo-yrfvv

  1. Set the initial index prop to undefined. First render is on index 0 as expect.
  2. Interact with the slider to go to a different index. In the demo swipe to slide 3.
  3. Cause an event which re-renders the SwipeableViews component, now set index to 1. In the demo click the Go back to the first slide button
  4. Component should animate back to index 0. Instead nothing happens on the re-render.

If you change the setIndex(0) call to 1 instead of 0 in my demo, it will correctly go to that slide, however only once. This appears to relate to not being able to go to the index value of the previous render.

Context

In my application I'm attempting to go "back" to the initial slide if something happens asynchronously. However due to this bug I'm having to side step it by unmounting the component then re-rendering it, which makes me lose the slick animation unfortunately.

Your Environment

Tech Version
react-swipeable-views 0.13.3
React 16.10.2
platform browser
@vicasas
Copy link

vicasas commented Mar 19, 2021

I don't think this is a mistake at all. To do this you can use onChangeIndex to control the change of the slide. As in this example.

https://codesandbox.io/s/swipeableviews-back-first-slide-forked-exgwk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants