'How to properly use ref with indiana drag scroll to set initial scroll position
I've been trying to implement the initial scroll from https://codesandbox.io/s/react-indiana-drag-scroll-initial-scroll-getelement-99o6q?file=/index.js:317-382
But haven't had much luck getting the ref to work it seems, or perhaps it is something with the render cycle.
Here is my code to reference with the codesandbox:
export default function ProjectCarousel() {
const container = useRef(null);
useEffect(() => {
container.current.getElement().scrollTo(0, 240);
}, []);
return (
<ScrollContainer className="scroll-container" ref={container}>
{ProjectData.map(({ id, ...otherProps }) => (
<ProjectImage key={id} {...otherProps} />
))}
</ScrollContainer>
);
}
Thanks for any help in advance
Solution 1:[1]
You have to use property innerRef
instead on ref
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Michele Sapignoli |