common-hook
Version:
提供项目中常用的 React Hooks
98 lines (54 loc) • 4.77 kB
Markdown
<h1 align="center">common-hook</h1>
<div align="center">
English | [简体中文](./README-zh_CN.md)
</div>
> Front-end business code tool library
Provide the commonly used React Hooks in the project, and the input and output functions do a special treatment to avoid closure problems, including a wealth of basic Hooks and refined from the business of advanced Hooks.
### Install
```js
npm i common-hook
```
```js
yarn add common-hook
```
### Demand Loading
> Default support for ES Modules-based Tree Shaking
```js
import { useMount, useUnmount } from "common-hook"
useMount(() => {
console.log("useMount")
})
useUnmount(() => {
console.log("useUnmount")
})
```
## :package: API Documentation
### Advanced Hooks
####   [useLatest](https://github.com/JainaXiong/common-hook/blob/main/src/advanced/useLatest.ts)    The returned value is always the latest
### Dom Hooks
####   [useEventListener](https://github.com/JainaXiong/common-hook/blob/main/src/dom/useEventListener.ts)    Event Listener
####   [useTitle](https://github.com/JainaXiong/common-hook/blob/main/src/dom/useTitle.ts)    Set page title
####   [useFavicon](https://github.com/JainaXiong/common-hook/blob/main/src/dom/useFavicon.ts)    Set page favicon
####   [useHover](https://github.com/JainaXiong/common-hook/blob/main/src/dom/useHover.ts)    Listen to DOM elements for mouse hover
####   [useMouse](https://github.com/JainaXiong/common-hook/blob/main/src/dom/useMouse.ts)    Listen to mouse position
### Effect Hooks
####   [useUpdateEffect](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useUpdateEffect.ts)    Not executed for the first time, only when dependencies are updated
####   [useDeepCompareEffect](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useDeepCompareEffect.ts)    When a dependency is updated, a deep comparison is performed
####   [useAsyncEffect](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useAsyncEffect.ts)    Support asynchronous functions
####   [useLockFn](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useLockFn.ts)    Add a competing lock to an asynchronous function to prevent concurrent execution
####   [useDebounceEffect](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useDebounceEffect.ts)    useEffect + Debounce
####   [useDebounceFn](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useDebounceFn.ts)    Hooks to handle debounce
####   [useThrottleEffect](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useThrottleEffect.ts)    useEffect + Throttle
####   [useThrottleFn](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useDebounceFn.ts)    Hooks to handle debounce
####   [useInterval](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useInterval.ts)    Hooks to handle setInterval
####   [useTimeout](https://github.com/JainaXiong/common-hook/blob/main/src/effect/useTimeout.ts)    Hooks to handle setTimeout
### LifeCycle Hooks
####   [useMount](https://github.com/JainaXiong/common-hook/blob/main/src/lifeCycle/useMount.ts)    Executed when the component is first rendered
####   [useUnmount](https://github.com/JainaXiong/common-hook/blob/main/src/lifeCycle/useUnmount.ts)    Execute on component unmount
### State Hooks
####   [useSetState](https://github.com/JainaXiong/common-hook/blob/main/src/state/useSetState.ts)    Hooks to manage object type states
####   [useBoolean](https://github.com/JainaXiong/common-hook/blob/main/src/state/useBoolean.ts)    Toggle boolean to receive default value
####   [useToggle](https://github.com/JainaXiong/common-hook/blob/main/src/state/useToggle.ts)    Hooks to switch between two state values
####   [useDebounce](https://github.com/JainaXiong/common-hook/blob/main/src/state/useDebounce.ts)    Hook for handling debounce values
####   [useThrottle](https://github.com/JainaXiong/common-hook/blob/main/src/state/useThrottle.ts)    Hook for handling throttle values
####   [useRafState](https://github.com/JainaXiong/common-hook/blob/main/src/state/useRafState.ts)    Update state only on requestAnimationFrame callback