# @ashalfarhan/hooks

> > Just a simple React Hooks

Latest version **0.2.3** (published 2021-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ashalfarhan/hooks
pnpm add @ashalfarhan/hooks
yarn add @ashalfarhan/hooks
bun add @ashalfarhan/hooks
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2021-11-06 |
| First published | 2021-07-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 25.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | ashalfarhan |
| Maintainers | ashalfarhan |
| Keywords | react, react-hooks, hooks, useToggle, use-toggle, useSafeUpdate, use-safe-update, useDebouncedValue, use-debounced-value |

## Links

- npm: https://www.npmjs.com/package/@ashalfarhan/hooks
- Repository: https://github.com/ashalfarhan/hooks
- Homepage: https://github.com/ashalfarhan/hooks#readme
- Issues: https://github.com/ashalfarhan/hooks/issues
- npm.io page: https://npm.io/package/@ashalfarhan/hooks

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2021-11-06
- 0.2.2 — 2021-07-15
- 0.2.0 — 2021-07-15
- 0.1.0 — 2021-07-11

## README

# Minimal React Hooks

> Just a simple React Hooks

## 📦 Installation

---

```bash
yarn add @ashalfarhan/hooks

#or

npm install @ashalfarhan/hooks --save
```

## 🔧 Guide

---
### 🧲 useToggle

```tsx
const { open, onToggle, onOpen, onClose, onSwitch } = useToggle();
```

- open

  > `boolean`
  >
  > Current state of toggle
  >
  > Note: Initially false, to change the initial state pass `true` to the `useToggle` parameter

- onToggle

  > `function`
  >
  > Function to toggle the state

- onClose

  > `function`
  >
  > Function to set the state to `false`

- onOpen

  > `function`
  >
  > Function to set the state to `true`

- onSwitch

  > `function`
  >
  > Function to set the state to the param that passed in

### 🦺 useSafeUpdate

```tsx
const [count, setCount] = useState(0)
const safeSetCount = useSafeUpdate(setCount)
```
#### Returns
 - safeCallback
    > `function`
    > 
    > Function/callback that is safe when you call if your component accidently unmounted.


### 🦥 useDebouncedValue

```tsx
const [searchQuery, setSearchQuery] = useState("")
const debouncedSearchQuery = useDebouncedValue(searchQuery)
```

#### Returns
 - debouncedValue
    > `T`
    >
    > Value that lazily update based on delay argument, default to `200` (in ms)

### 👈 usePreviousValue
```tsx
const prevCount = usePrevious(count)
```

### Returns
 - previousValue
   > `T`
   >
   > The prevous value of every render, possibly undefined at first

---
_Source: https://npm.io/package/@ashalfarhan/hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
