[Beta] feat: alternative solution for scrolling image carousel - #5099
Open
gsong wants to merge 1 commit into
Open
[Beta] feat: alternative solution for scrolling image carousel#5099gsong wants to merge 1 commit into
gsong wants to merge 1 commit into
Conversation
Size ChangesDetails📦 Next.js Bundle AnalysisThis analysis was generated by the next.js bundle analysis action 🤖 This PR introduced no changes to the javascript bundle 🙌 |
gsong
force-pushed
the
suggest/manipulating-the-dom-with-refs
branch
from
September 29, 2022 16:26
434a33c to
d4eae53
Compare
gsong
force-pushed
the
suggest/manipulating-the-dom-with-refs
branch
from
October 7, 2022 23:10
d4eae53 to
330431b
Compare
eps1lon
reviewed
Oct 8, 2022
| <button onClick={() => { | ||
| const nextIndex = index < catList.length - 1 ? index + 1 : 0; | ||
| setIndex(nextIndex); | ||
| listRef.current.children.item(nextIndex).scrollIntoView({ |
Member
There was a problem hiding this comment.
The upside of the prior solution is that it even works if the component implementation (or a children) adds intermediate DOM nodes (e.g. separators).
The proposed, alternative implementation relies on a specific DOM structure.
Generally, if we show alternatives we should spell out what pros and cons of those are so that people can make an informed decision which to choose. Right now it's just personal preference which I feel like is not appropriate for a tutorial. Curious what @gaearon thinks about this.
@gsong What would you say are the benefits of your implementation?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Image carousel alternate solution using a ref on the list itself.