maxmarinich / react-alice-carousel

React responsive component for building content galleries, content rotators and any React carousels
MIT License
832 stars 91 forks source link

Is there a way to have an onUpdate method? #293

Closed bogdancss closed 1 year ago

bogdancss commented 1 year ago

Is there a way to have an onUpdate method?

I need to know the itemsInSlide after I add new items to the carousel.

I set this to a visibileItems state through the onInitialise and onResize methods, but I'd need it on and onUpdate as well

maxmarinich commented 1 year ago

Hi, @bogdancss! You don't need any event to check if any element is new. Because you are passing props (like items) from above. After all, if you passed the updated props to the carousel, you fire the update event yourself. Events example is here

bogdancss commented 1 year ago

Hei @maxmarinich I get that, but we have a check that disables the prev/next carousel buttons based on isNextSlideDisabled and isPrevSlideDisabled from the carousel EventObject I get access to this event in the onResized and onInitialized methods which works fine on init or resize.

However we have the ability to add/remove items after init - when we add/remove am item to/from the carousel, we need to update the prev/next buttons. Obviously the onResized and onInitialized methods are not triggered here, so there is no way to determine if these buttons should be active or not.

bogdancss commented 1 year ago

@maxmarinich I noticed the UPDATE event is there, just there is not way to subscribe to it:

enum EventType {
  ACTION = 'action', // used if a general user action (button click or swipe)
  INIT = 'init',     // used if the initial event was triggered
  RESIZE = 'resize', // used if the gallery size was changed
  UPDATE = 'update', // used if the gallery was updated with props (activeIndex)
}