@cantabile/hooks
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

@cantabile/hooks

This package provides a collection of custom React hooks to enhance your React applications with common functionalities.

Installation

You can install the package using npm or yarn:

npm install @cantabile/hooks

or

yarn add @cantabile/hooks

Available Hooks

1. useClock

import { useClock } from "@cantabile/hooks";

const currentTime = useClock();

Returns the current time and updates it every second.

2. useImage

import { useImage } from "@cantabile/hooks";

const imageUrl = useImage({ src: "image-url.jpg" });

Fetches an image from the provided URL and returns its URL as a blob.

3. useOutsideAlerter

import { useOutsideAlerter } from "@cantabile/hooks";

useOutsideAlerter(ref, () => {
  // Handle outside click
});

Detects clicks outside a specified DOM element and triggers a callback.

4. useWindowSize

import { useWindowSize } from "@cantabile/hooks";

const [width, height] = useWindowSize();

Returns the current width and height of the window and updates them on window resize.

5. useBreakpoint

import { useBreakpoint } from "@cantabile/hooks";

const isMobile = useBreakpoint(768);

Detects if the window width is less than the specified breakpoint.

6. useElementSize

import { useElementSize } from "@cantabile/hooks";

const [width, height] = useElementSize(ref);

Returns the width and height of a specified DOM element and updates them on window resize.

7. useReMountComponent

import { useReMountComponent } from "@cantabile/hooks";

const refreshCount = useReMountComponent();

Remounts the component after a specified time interval when the window loses focus.

8. useOrientation

import { useOrientation } from "@cantabile/hooks";

const orientation = useOrientation();

Returns the current orientation of the device (portrait or landscape) and updates it on orientation change.

9. useQueryParams

import { useQueryParams } from "@cantabile/hooks";

const queryParams = useQueryParams(["param1", "param2"]);

Returns an object containing query parameters extracted from the URL.

10. useSetQueryParams

import { useSetQueryParams } from "@cantabile/hooks";

const setQueryParam = useSetQueryParams();

Allows setting query parameters in the URL.

11. useDebounce

import { useDebounce } from "@cantabile/hooks";

useDebounce(() => {
  // Handler
}, 1000);

Delays executing a function until after a specified delay.

12. useModalState

import { useModalState } from "@cantabile/hooks";

const { state, open, close, toggle } = useModalState();

Manages the state of a modal, providing functions to open, close, and toggle its visibility.

License

This package is licensed under the MIT License. See the LICENSE file for details.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.31latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.31
1.1.21
1.1.11
1.1.01
1.0.11
1.0.01

Package Sidebar

Install

npm i @cantabile/hooks

Weekly Downloads

6

Version

1.1.3

License

ISC

Unpacked Size

41.9 kB

Total Files

36

Last publish

Collaborators

  • cantabile