Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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.
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>;
}
react-use is a collection of essential React Hooks that provides a wide range of hooks for state management, lifecycle, sensors, and more. It is similar to ahooks in terms of the variety and utility of hooks offered, but it has a different set of hooks and may have different implementations for similar functionalities.
usehooks-ts is a collection of React hooks written in TypeScript. It offers a variety of hooks for state management, side effects, and more. Compared to ahooks, usehooks-ts is specifically designed for TypeScript users, providing type-safe hooks out of the box.
react-hooks-library is another collection of reusable React hooks. It focuses on providing hooks for common use cases like state management, side effects, and lifecycle methods. While it offers similar functionalities to ahooks, it may have a smaller set of hooks and different API designs.
:warning: This is v3 branch, find v2 from https://github.com/alibaba/hooks/tree/release/v2.x
$ npm install --save ahooks
# or
$ yarn add ahooks
import { useRequest } from 'ahooks';
$ git clone git@github.com:alibaba/hooks.git
$ cd hooks
$ yarn run init
$ yarn start
Open your browser and visit http://127.0.0.1:8000
We welcome all contributions, please read our CONTRIBUTING.MD first, let's build a better hooks library together.
Thanks to all the contributors:
FAQs
react hooks library
The npm package ahooks receives a total of 157,662 weekly downloads. As such, ahooks popularity was classified as popular.
We found that ahooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.