Socket
Socket
Sign inDemoInstall

@restart/hooks

Package Overview
Dependencies
4
Maintainers
3
Versions
65
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @restart/hooks

A set of utility and general-purpose React hooks.


Version published
Maintainers
3
Install size
206 kB
Created

Package description

What is @restart/hooks?

The @restart/hooks npm package provides a collection of reusable React hooks that help manage various aspects of a React application, such as state, effects, and lifecycle events. These hooks are designed to simplify common patterns and abstract complex behaviors into reusable functions.

What are @restart/hooks's main functionalities?

useStatefulRef

This hook creates a mutable ref object that holds a value which can be changed without causing a component re-render, similar to useRef but with a stateful value.

import { useStatefulRef } from '@restart/hooks';

function MyComponent() {
  const ref = useStatefulRef(null);

  // ref.current is now mutable and can be updated without causing a re-render
  return <div ref={ref}>Hello, world!</div>;
}

useEventCallback

This hook ensures that a callback function remains stable between renders, preventing unnecessary re-renders of child components that might be sensitive to prop changes.

import { useEventCallback } from '@restart/hooks';

function MyComponent({ onClick }) {
  const stableOnClick = useEventCallback(onClick);

  // stableOnClick will not change between renders, preventing unnecessary re-renders of child components
  return <button onClick={stableOnClick}>Click me</button>;
}

useMounted

This hook provides a function to check if the component is still mounted before performing any actions that may result in a state update, which can help avoid memory leaks and errors.

import { useMounted } from '@restart/hooks';

function MyComponent() {
  const isMounted = useMounted();

  useEffect(() => {
    const timer = setTimeout(() => {
      if (isMounted()) {
        // Perform some action only if the component is still mounted
      }
    }, 1000);

    return () => clearTimeout(timer);
  }, [isMounted]);

  return <div>Timer example</div>;
}

Other packages similar to @restart/hooks

Changelog

Source

0.4.16 (2024-02-10)

Bug Fixes

  • useDebouncedCallback: fix behavior in strict mode (#98) (9a01792)

Readme

Source

@restart/hooks npm

A set of utility and general-purpose React hooks.

Install

npm install @restart/hooks

Usage

import useInterval from '@restart/hooks/useInterval'

useInterval(() => loop(), 300, false)

FAQs

Last updated on 10 Feb 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc