React-slick: beforeChange() breaks fade

Created on 3 May 2018  路  5Comments  路  Source: akiran/react-slick

Sandbox: https://codesandbox.io/s/2j3onlv9rn
Removing either beforeChange() or fade restores normal behaviour. But I would want to use both :)

NOTE: changing to afterChange() will make slider work, but still mess up the state changes.

Most helpful comment

I had the same issue. And what I noticed is that if you setState on beforeChange with fade: true, it breaks the sliders. The kind of hack I used was to delay my setState by 10 milliseconds using setTimeout() and then it works fine.

@akiran Can you give some insight as why it happens?

All 5 comments

Same issue

I had the same issue. And what I noticed is that if you setState on beforeChange with fade: true, it breaks the sliders. The kind of hack I used was to delay my setState by 10 milliseconds using setTimeout() and then it works fine.

@akiran Can you give some insight as why it happens?

I was having the same problem with the React Hooks fade, I disabled this option in the project and everything went back to normal.

I was using react hook, but @sayedtaqui hack doesn't work for me

const [slideState, setSlideState] = useState({
        activeSlide: 0,
        activeSlide2: 0
    });

beforeChange: (current, next) => {
            setTimeout(() =>{
                setSlideState({...slideState, activeSlide: next})

            }, 10)
        },
         afterChange: current => {
                 setSlideState( {...slideState, activeSlide2: current} );
         },

In my case, the slider would not change slides unless you clicked twice, and beforeChange would get called on the second click.

I was able to work around this bug using setTimeout like so:

beforeChange: (current, next) => { setTimeout(() => onSlideChange(next), 10); }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicreichert picture nicreichert  路  3Comments

enriquelopez-atlas picture enriquelopez-atlas  路  3Comments

slashwhatever picture slashwhatever  路  3Comments

amishPro picture amishPro  路  3Comments

quarklemotion picture quarklemotion  路  4Comments