Skip to content

[Beta] feat: alternative solution for scrolling image carousel - #5099

Open
gsong wants to merge 1 commit into
reactjs:mainfrom
gsong:suggest/manipulating-the-dom-with-refs
Open

[Beta] feat: alternative solution for scrolling image carousel#5099
gsong wants to merge 1 commit into
reactjs:mainfrom
gsong:suggest/manipulating-the-dom-with-refs

Conversation

@gsong

@gsong gsong commented Sep 23, 2022

Copy link
Copy Markdown
Contributor

Image carousel alternate solution using a ref on the list itself.

@github-actions

github-actions Bot commented Sep 23, 2022

Copy link
Copy Markdown

Size Changes

Details

📦 Next.js Bundle Analysis

This analysis was generated by the next.js bundle analysis action 🤖

This PR introduced no changes to the javascript bundle 🙌

@gsong
gsong force-pushed the suggest/manipulating-the-dom-with-refs branch from d4eae53 to 330431b Compare October 7, 2022 23:10
@gsong gsong changed the title [beta] feat: alternative solution for scrolling image carousel [Beta] feat: alternative solution for scrolling image carousel Oct 7, 2022
<button onClick={() => {
const nextIndex = index < catList.length - 1 ? index + 1 : 0;
setIndex(nextIndex);
listRef.current.children.item(nextIndex).scrollIntoView({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants