🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Book a DemoInstallSign in
Socket

ahooks

Package Overview
Dependencies
Maintainers
5
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ahooks

react hooks library

3.8.5
latest
Source
npm
Version published
Weekly downloads
361K
10.65%
Maintainers
5
Weekly downloads
 
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 19 May 2025

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