Add autoRefreshCondition optional prop to useSnapCarousel #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this add?
This adds a new prop,
autoRefreshCondition ?: () => boolean = () => true;
. This prop lets an implementation enable or disable uncontrolled refreshes, e.g. on scroll, on resize, etc.Why is this important?
Allowing implementation control of auto-refresh enables more fine-grained control over the application's UI state. Additionally, the overhead required to add this functionality is minimal.
Example Use Case
The main reason I added this was to allow switching between a carousel view and an "expanded" view. This really only toggles a class that adds
flex-wrap: wrap;
to the carousel. I also want to be able to hide this functionality when the expanded view isn't required, and to do so, I rely onpages.length
(whenpages.length > 1
, show the toggle). The downside here is that if I add wrapping to the carousel and the layout changes, pages.length automatically changes to 1 and I can no longer access the toggle from that point forward. Being able to disable uncontrolled refreshes will enable this use case.