Emiliano-Bucci / react-spring-carousel-js

A new Carousel experience for the modern Web
https://react-spring-carousel-js.emilianobucci.com
80 stars 6 forks source link

Easiest way to check if next or previous item exists. #15

Closed jbowa closed 3 years ago

jbowa commented 3 years ago

Hey Emiliano,

I can't see this from the current API - but is there a way to check if next or previous items exist? It would be useful in rendering the back and forward buttons if we had hasNext: boolean or hasPrevious: boolean which would allow us to conditionally render the buttons. Thank you

Emiliano-Bucci commented 3 years ago

@jbowa Hi! Regarding this, i thought about introducing it, but this means that i need to keep a state variable inside the carousel, which means that i will need to trigger a React re rendering, which i want to avoid as much as possible for performance reasons (also because i would add something that maybe not anyone needs). I guess that you can replicate the logic outside the carousel and using the useListenToCustomEvent and checking the current active item and matching with your array of items. I've done that in other projects. Please let me know if that can help :)

jbowa commented 3 years ago

This makes a lot of sense, I will go with useListenToCustomEvent - Thank you for all the great work!