Socket
Book a DemoInstallSign in
Socket

ahooks

Package Overview
Dependencies
Maintainers
4
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ahooks

react hooks library

3.7.5
Source
npmnpm
Version published
Maintainers
4
Created

What is ahooks?

ahooks is a high-quality and reliable React Hooks library that provides a comprehensive set of hooks to enhance your React development experience. It includes a wide range of hooks for state management, side effects, lifecycle, and more.

What are ahooks's main functionalities?

State Management

The useBoolean hook provides a simple way to manage boolean state with additional methods to toggle, set true, and set false.

import { useBoolean } from 'ahooks';

function App() {
  const [state, { toggle, setTrue, setFalse }] = useBoolean(false);

  return (
    <div>
      <p>State: {state.toString()}</p>
      <button onClick={toggle}>Toggle</button>
      <button onClick={setTrue}>Set True</button>
      <button onClick={setFalse}>Set False</button>
    </div>
  );
}

Side Effects

The useDebounceEffect hook allows you to debounce side effects, which is useful for scenarios like search input where you want to delay the execution of a function.

import { useDebounceEffect } from 'ahooks';

function App() {
  const [value, setValue] = useState('');

  useDebounceEffect(() => {
    console.log('Debounced value:', value);
  }, [value], { wait: 500 });

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

Lifecycle

The useMount hook runs a function once when the component is mounted, similar to componentDidMount in class components.

import { useMount } from 'ahooks';

function App() {
  useMount(() => {
    console.log('Component mounted');
  });

  return <div>Check the console</div>;
}

Other packages similar to ahooks

Keywords

ahooks

FAQs

Package last updated on 28 Feb 2023

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.