This package provides a custom hook for smooth horizontal scrolling in React. The hook allows for setting a scroll container, handling scroll events, scrolling to a specific point, and determining if the user is at the start or end of the scrollable area.
npm install use-smooth-horizontal-scrollA small utility hook for adding smooth horizontal scrolling to your React project.
```
npm install use-smooth-horizontal-scroll`
or`
yarn add use-smooth-horizontal-scroll
`tsx`
import useSmoothHorizontalScroll from 'use-smooth-horizontal-scroll';
Then, use the hook in your component:
`tsx`
const { scrollContainerRef, handleScroll, scrollTo, isAtStart, isAtEnd } = useSmoothHorizontalScroll();
You'll need to pass the scrollContainerRef to the element you want to apply the smooth scrolling to, and attach the handleScroll function to the onScroll event of that element.
`tsx`
{/ Your content here /}
You can use the scrollTo function to scroll to a specific position, or scroll by a specific amount.
`tsx`
You can also check the isAtStart and isAtEnd state to disable buttons for scrolling if the user has reached the start or end of the content.
`tsx`
tsx
import { useRef, useState } from "react";
import useSmoothHorizontalScroll from "use-smooth-horizontal-scroll";const MyComponent = () => {
const { scrollContainerRef, handleScroll, scrollTo, isAtStart, isAtEnd } = useSmoothHorizontalScroll();
return (
{/ Your scrolling content here /}
);
};
``