akiran / react-slick

React carousel component
http://react-slick.neostack.com/
MIT License
11.61k stars 2.09k forks source link

fix: set slider wrapper key based on children keys passed #2288

Open jamessspanggg opened 9 months ago

jamessspanggg commented 9 months ago

Context

Currently react-slick does not support dynamic children, where if any of the children is updated after the slider is mounted, the slider does not re-render accordingly. This is due to the wrapper component having it's own key calculation that does not take into account the children's keys that was passed.

In my work, we were facing issues where even the children were updated after mounting, the slider does not re-render the children accordingly. I had to fork the this repo's code to our code and made the changes in this PR in order for it to work.

Some existing issues that reported the same issue:

Solution

Utilise a combination of the children's key for the wrapper, this ensures that if any of the children's key updates, the wrapper knows to re-render accordingly.

Unit tests are all passing after the changes:

Screenshot 2023-10-01 at 7 20 44 PM
jamessspanggg commented 9 months ago

@akiran appreciate it if you could take some time out to look at this fix for the PR as it might help out other people that uses ur package 🙏