npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@anton.bobrov/react-hooks

v3.1.1

Published

A collection of custom React hooks and utility functions designed to simplify component logic and enhance performance.

Downloads

2,373

Readme

@anton.bobrov/react-hooks

A collection of custom React hooks and utility functions designed to simplify component logic and enhance performance. This library provides a robust set of hooks with full TypeScript support, offering solutions for common patterns in modern React applications.

Links

Installation

To install the package, use npm:

npm i "@anton.bobrov/react-hooks"

Usage

Here's an example of how to use one of the hooks, useDebouncedEffect, in your component:

import { useDebouncedEffect } from '@anton.bobrov/react-hooks';
import React, { useState } from 'react';

export const MyComponent = () => {
  const [value, setValue] = useState('');

  useDebouncedEffect(
    () => {
      console.log('Debounced effect executed with value:', value);
    },
    [value],
    300, // Debounce delay in milliseconds
  );

  return (
    <input
      type="text"
      value={value}
      onChange={(e) => setValue(e.target.value)}
    />
  );
};

Available Hooks

Here are the available hooks and what they do:

  • useChange: Tracks changes to a property.
  • useClientHeight: Retrieves and tracks the client height of an element.
  • useClientSize: Retrieves and tracks the client width and height of an element.
  • useClientWidth: Retrieves and tracks the client width of an element.
  • useDebouncedEffect: Runs an effect after a specified debounce delay.
  • useDebouncedEvent: Debounces a callback.
  • useDebouncedProp: Debounces updates to a prop value.
  • useDomId: Generates a unique DOM element ID.
  • useDOMRect: Tracks the size and position of an element.
  • useEvent: Create a stable link for a callback function.
  • useEventListener: Adds event listeners to DOM elements.
  • useFocus: Detects focus state of an element.
  • useFocusIn: Detects focus inside a given element.
  • useFocusTrap: Traps focus within a specific container.
  • useForwardedRef: Forwards refs in components.
  • useHover: Detects hover state on an element.
  • useIntersectionObserver: Uses the IntersectionObserver API to track visibility of elements.
  • useInViewport: Detects when an element enters or leaves the viewport.
  • useIsOnceMounted: Returns true if the component has been mounted once.
  • useLazyReady: Tracks element visibility with lazy loading behavior.
  • useLiteInteraction: Detect a slight user interaction with elements.
  • useLocalStorage: A hook to work with the localStorage API.
  • useMouseClientPosition: Tracks the mouse position relative to the client window.
  • useOffsetHeight: Retrieves and tracks the offset height of an element.
  • useOffsetSize: Tracks the offset size of an element.
  • useOffsetWidth: Retrieves and tracks the offset width of an element.
  • useOnceProp: Updates the state only once when the current value matches the target value.
  • useOnElementResize: Listens for resize events on a specific element.
  • useOnEscape: Executes a callback when the Escape key is pressed.
  • useOutsideClick: Detects clicks outside a specific element.
  • usePointerHover: Detects hover state using pointer events.
  • usePreventDocumentScrolling: Temporarily prevents document scrolling.
  • usePrevious: Tracks the previous value of a variable.
  • usePropState: Creates a state that automatically synchronizes with an external value.
  • useScrollLock: Locks the scroll behavior of an element.

Available Utilities

In addition to hooks, the package also provides several utility functions:

  • objectKeys: Retrieves the keys of an object as an array of the object's keys.
  • pickObjectProps: Pick specific properties from an object.
  • times: Repeats a function n times and returns an array of the results.
  • splitIntoChunks: Splits an array into chunks.
  • uniqueArray: Returns an array with unique values.
  • addEventListener: Adds an event listener to a target.
  • getSiblingsFocusableElements: Retrieves focusable sibling elements.
  • resetFocus: Resets focus to a specific element.
  • selectFocusableChildren: Selects focusable children within an element.
  • isBrowser: Checks if the code is running in a browser environment.
  • isServer: Checks if the code is running in a server environment.
  • getRandomInt: Generates a random integer.
  • cleanTelephone: Cleans telephone strings.
  • removeDuplicateSlashes: Removes duplicate slashes from a URL or path.
  • isBoolean: Checks if a value is a boolean.
  • isNumber: Checks if a value is a number.
  • isString: Checks if a value is a string.
  • isUndefined: Checks if a value is undefined.

License

This project is licensed under the terms of the MIT license.