Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
use-carousel-hook
Advanced tools
useCarousel is a React hook for adding functions to create a sliding carousel.
No styling is included, the hook returns functions to integrate into your slider to allow for full flexibility and control over the carousel you create.
Typescript definitions are included.
Call the useCarousel hook in your code. This will return the following values as an object.
Property | Type | Description |
---|---|---|
ref | React.MutableRefObject<HTMLDivElement> | Attach this ref to your carousel element that contains your cards/elements. |
previous | () => void; | Go to the previous element in the carousel. |
next | () => void; | Go to the next element in the carousel. |
setCurrent | (current: number) => void; | Go to a specific element index in the carousel. |
reset | () => void; | Go to the beginning of the carousel. |
position | { isAtStart: boolean; isAtEnd: boolean } | Position of the carousel. Can be used to disable next/previous buttons if needed. |
import React from 'react';
import { useCarousel } from 'use-carousel-hook';
import { Inner, Item } from './carousel.styled';
const Carousel: React.FC = () => {
const { ref, previous, next, setCurrent, reset } = useCarousel();
return (
<div>
<button onClick={previous}>Previous</button>
<button onClick={next}>Next</button>
<button onClick={reset}>Reset</button>
<button onClick={() => setCurrent(2)}>Set index to 2</button>
<Inner ref={ref}>
<Item>Item 1</Item>
<Item>Item 2</Item>
<Item>Item 3</Item>
<Item>Item 4</Item>
</Inner>
</div>
);
};
export default Carousel;
Option | Type | Default value |
---|---|---|
scrollBehavior | 'smooth' | 'auto' | 'smooth' |
direction | 'horizontal' | 'vertical' | 'horizontal' |
const { ref, previous, next } = useCarousel({ scrollBehavior: 'auto', direction: 'vertical' });
[0.0.2]
FAQs
Adds functionality for carousels using React hooks
The npm package use-carousel-hook receives a total of 360 weekly downloads. As such, use-carousel-hook popularity was classified as not popular.
We found that use-carousel-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.