# @saasquatch/universal-hooks

> An interface and a swappable implementation that can be used to implement universal custom hooks on top of hooks.

Latest version **1.0.1** (published 2023-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @saasquatch/universal-hooks
pnpm add @saasquatch/universal-hooks
yarn add @saasquatch/universal-hooks
bun add @saasquatch/universal-hooks
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-04-20 |
| First published | 2021-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | ReferralSaaSquatch.com, Inc. |
| Maintainers | tdgao, locrian, jayden-chan, zachharrison, logvol, lisq, 00salmon, johanventer, dereksiemens, squatch-noahwc, ianhitchcock |

## Links

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

## Recent versions

- 1.0.1 (latest) — 2023-04-20
- 1.0.0 — 2021-04-21
- 0.1.3 — 2021-03-09
- 0.1.2 — 2021-03-08
- 0.1.1 — 2021-03-08
- 0.1.0 — 2021-03-08

## README

# Universal Hooks

This library aims to provide a common interface for React-like hooks to plug into. Simply plug in an implementation and your hooks are reusable across different implementations.

## Usage

There are two ways to plug in an implementation. You can supply a module at runtime or you can replace Universal Hooks at compile time.

### Provide an implementation at runtime

```javascript
// Set an implementation for the hooks
setImplementation(haunted)
// OR
setImplementation(React)
// OR
setImplementation(Preact)

// Use the hooks like normal
function useCounter() {
    const [counter, setCounter] = useState(0);

    const increment = () => setCounter((c) => c + 1)
    const decrement = () => setCounter((c) => c - 1)

    return {counter, increment, decrement}
}
```

### Provide an implementation via bundlers

Rollup, Webpack and other bundlers allow compile-time replacement of implementations.

E.g. with the Rollup `alias` plugin https://github.com/rollup/plugins/tree/master/packages/alias

To swap in React
```js
entries: [
  { find: '@saasquatch/universal-hooks', replacement: 'React' },
];
```

To swap in Haunted
```js
entries: [
  { find: '@saasquatch/universal-hooks', replacement: 'haunted' },
];
```


## API

Most common hooks are supported, except for `useContext`.

- useState
- useMemo
- useCallback
- useEffect
- useReducer
- useRef

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