Using document.querySelector in React? Should I use refs instead? How?

I can’t answer the “should you” part of whether to use refs for this instead other than if you do, you don’t need those id values unless you use them for something else. But here’s how you would: Use useRef(null) to create the ref. const activeSlideRef = useRef(null); Put it on the Slide that’s currently … Read more

scrollIntoView block vs inline

The block option decides where the element will be vertically aligned inside the visible area of its scrollable ancestor: Using {block: “start”}, the element is aligned at the top of its ancestor. Using {block: “center”}, the element is aligned at the middle of its ancestor. Using {block: “end”}, the element is aligned at the bottom … Read more

scrollintoview animation

In most modern browsers (Chrome and Firefox, but not Safari, UC, or IE) you can pass options in an object to .scrollIntoView(). Try this: elm.scrollIntoView({ behavior: ‘smooth’, block: ‘center’ }) Other values are behavior: ‘instant’ or block: ‘start’ or block: ‘end’. See https://developer.mozilla.org/en/docs/Web/API/Element/scrollIntoView

Scroll Automatically to the Bottom of the Page

jQuery isn’t necessary. Most of the top results I got from a Google search gave me this answer: window.scrollTo(0, document.body.scrollHeight); Where you have nested elements, the document might not scroll. In this case, you need to target the element that scrolls and use it’s scroll height instead. window.scrollTo(0, document.querySelector(“.scrollingContainer”).scrollHeight); You can tie that to the … Read more