# @jrop/hooks

> [![pipeline status](https://gitlab.com/jrop/react-hooks/badges/master/pipeline.svg)](https://gitlab.com/jrop/react-hooks/-/commits/master)

Latest version **0.0.14** (published 2023-10-14) · ISC license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.14 |
| Published | 2023-10-14 |
| First published | 2020-09-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jrop |

## Links

- npm: https://www.npmjs.com/package/@jrop/hooks
- npm.io page: https://npm.io/package/@jrop/hooks

## Recent versions

- 0.0.14 (latest) — 2023-10-14
- 0.0.14-next.0 (next) — 2023-12-01
- 0.0.13 — 2023-10-14
- 0.0.12 — 2023-10-13
- 0.0.11 — 2023-10-12
- 0.0.10 — 2023-10-12
- 0.0.9 — 2023-10-12
- 0.0.8 — 2022-12-01
- 0.0.7 — 2022-11-26
- 0.0.6 — 2022-11-26
- 0.0.5 — 2022-11-26
- 0.0.4 — 2022-08-15
- 0.0.3 — 2021-06-30
- 0.0.2 — 2020-10-04
- 0.0.1 — 2020-09-26

## README

# @jrop's React Hooks

[![pipeline status](https://gitlab.com/jrop/react-hooks/badges/master/pipeline.svg)](https://gitlab.com/jrop/react-hooks/-/commits/master)

## useAsync

## useControlled

`function useControlled<T>(prop: T|undefined, initialValue: T|(() => T), onChange?: (x: T) => any)`

A handy utility for creating optional prop-controlled components. Uses `React.useState`, internally.

For example:

```typescript
const MyTextInput = (props: {value?: string, onValueChanged?: (newValue: string) => any}) => {
  const [value, setValue] = useControlled(props.value, "", props.onValueChanged);
  // any calls to setValue will automatically call onValueChanged
  // will work for controlled/uncontrolled mode (i.e., whether or not props.value is provided)
  // ...
}
```

## useControlledReducer

`function useControlledReducer<A, T>(prop: T|undefined, initialValue: T|(() => T), reducer: (prevState: T, action: A) => T, onChange?: (x: T) => any)`

A handy utility for creating optional prop-controlled components. Uses `React.useReducer`, internally.

For example:

```typescript
const MyTextInput = (props: {value?: string, onValueChanged?: (newValue: string) => any}) => {
  const [value, dispatch] = useControlledReducer(props.value, "", (_state, action: string) => action, props.onValueChanged);
  // any calls to dispatch will automatically call onValueChanged
  // will work for controlled/uncontrolled mode (i.e., whether or not props.value is provided)
  // ...
}
```

## useMounted

`function useMounted(): boolean`

Returns whether the component is mounted.

## usePopup

## useWrappedCallback

`function useWrappedCallback<F extends Function>(f: F): F`

Wraps a function whose identity does not change across re-renders. That is, for:

```
const fn = useWrappedCallback(() => {});
```

...`fn` will always be the same reference.

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