# @backhooks/core

> This package holds the core of backhooks.

Latest version **0.3.0** (published 2023-02-03) · 0 weekly downloads

## Install

```sh
npm install @backhooks/core
pnpm add @backhooks/core
yarn add @backhooks/core
bun add @backhooks/core
```

## Health

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

Positive: has types; no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2023-02-03 |
| First published | 2023-01-17 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | coderhammer, hammerbot |

## Links

- npm: https://www.npmjs.com/package/@backhooks/core
- npm.io page: https://npm.io/package/@backhooks/core

## Recent versions

- 0.3.0 (latest) — 2023-02-03
- 0.2.2 — 2023-02-03
- 0.2.1 — 2023-01-19
- 0.2.0 — 2023-01-18
- 0.1.2 — 2023-01-18
- 0.0.2 — 2023-01-17
- 0.0.1 — 2023-01-17

## README

# Backhooks Core

This package holds the core of backhooks.

## Get started

```
npm install @backhooks/core
```

## Usage

`createHook: (options) => [hookFunction, hookConfigurationFunction]`

This allows you to create a hook. Example of creating a simple hook:

```ts
const [useCount, configureCountHook] = createHook({
  data() {
    return {
      count: 0,
    };
  },
  execute(state) {
    state.count++;
    return state.count;
  },
});
```

`runHookContext: <T>(fn: () => T): Promise<T>`

This allows you to run a hook context. Any hook called within the `runHookContext` callback will have a specific state attached to it:

```ts
runHookContext(() => {
  console.log(useCount()); // 1
  console.log(useCount()); // 2
  console.log(useCount()); // 3
});

runHookContext(() => {
  console.log(useCount()); // 1
  console.log(useCount()); // 2
  console.log(useCount()); // 3
});
```

`resetGlobalContext()`

This allows you to reset the global context. It can be very useful for testing purposes

```ts
beforeEach(() => {
  resetGlobalContext();
});

test("it should count", async () => {
  const count = useCount();
  expect(count).toBe(1); // true
});

test("it should also count", async () => {
  const count = useCount();
  expect(count).toBe(1); // also true
});
```

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