# @rest-hooks/experimental

> Experimental extensions for Rest Hooks

Latest version **9.4.1** (published 2023-03-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @rest-hooks/experimental
pnpm add @rest-hooks/experimental
yarn add @rest-hooks/experimental
bun add @rest-hooks/experimental
```

## Health

**Score 40/100 (D)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 9.4.1 |
| Published | 2023-03-30 |
| First published | 2021-05-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^12.17 \|\| ^13.7 \|\| >=14 |
| Dependencies | 3 |
| Unpacked size | 203.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2040 |
| Author | Nathaniel Tucker |
| Maintainers | ntucker, ljharb |
| Keywords | rest, react, flux, ajax, networking, fetch, hook, typescript, redux, data fetching, data cache, api, api call, normalized cache, swr |

## Links

- npm: https://www.npmjs.com/package/@rest-hooks/experimental
- Repository: https://github.com/data-client/rest-hooks
- Homepage: https://resthooks.io
- Issues: https://github.com/data-client/rest-hooks/issues
- npm.io page: https://npm.io/package/@rest-hooks/experimental

## Dependencies (3)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.17.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.0
- [@types/path-to-regexp](https://npm.io/package/@types/path-to-regexp.md) ^1.7.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 9.4.1 (latest) — 2023-03-30
- 7.1.0-beta.2 (beta) — 2022-09-19
- 9.4.0 — 2023-03-28
- 9.3.8 — 2023-03-19
- 9.3.7 — 2023-03-15
- 9.3.6 — 2023-03-12
- 9.3.5 — 2023-03-02
- 9.3.4 — 2023-02-21
- 9.3.3 — 2023-02-11
- 9.3.2 — 2023-01-30
- 9.3.1 — 2023-01-29
- 9.3.0 — 2023-01-23
- 9.2.5 — 2023-01-23
- 9.2.4 — 2023-01-13
- 9.2.3 — 2022-12-23
- … 47 more at https://npm.io/package/@rest-hooks/experimental/versions

## README

# Experimental extensions for Rest Hooks

[![CircleCI](https://circleci.com/gh/data-client/rest-hooks/tree/master.svg?style=shield)](https://circleci.com/gh/data-client/rest-hooks)
[![Coverage Status](https://img.shields.io/codecov/c/gh/data-client/rest-hooks/master.svg?style=flat-square)](https://app.codecov.io/gh/data-client/rest-hooks?branch=master)
[![npm downloads](https://img.shields.io/npm/dm/@rest-hooks/experimental.svg?style=flat-square)](https://www.npmjs.com/package/@rest-hooks/experimental)
[![bundle size](https://img.shields.io/bundlephobia/minzip/@rest-hooks/experimental?style=flat-square)](https://bundlephobia.com/result?p=@rest-hooks/experimental)
[![npm version](https://img.shields.io/npm/v/@rest-hooks/experimental.svg?style=flat-square)](https://www.npmjs.com/package/@rest-hooks/experimental)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)

<div align="center">

**[📖Read The Docs](https://resthooks.io)**

</div>

## Motivation

Field application of designs help smooth edges of a theoretical design. New designs can be iterated on here, breaking freely without worry of legacy support plans.

## Usage

### useController()

```tsx
const controller = useController();

return (
  <form onSubmit={() => controller.fetch(User.create(), userPayload)}>
    <button onClick={() => controller.fetch(User.list())}>Refresh list</button>
    <button onClick={() => controller.invalidate(User.list())}>Suspend list</button>
  </form>
);
```

### Endpoint.update

<details open><summary><b>Simple</b></summary>

```typescript
const createUser = new Endpoint(postToUserFunction, {
  schema: User,
  update: (newUserId: string) => ({
    [userList.key({})]: (users = []) => [newUserId, ...users],
  }),
});
```

</details>

<details><summary><b>Multiple updates</b></summary>

```typescript
const createUser = new Endpoint(postToUserFunction, {
  schema: User,
  update: (newUserId: string, newUser: User)  => {
    const updates = {
      [userList.key()]: (users = []) => [newUserId, ...users],
      [userList.key({ sortBy: 'createdAt' })]: (users = [], { sortBy }) => {
        const ret = [newUserId, ...users];
        ret.sortBy(sortBy);
        return ret;
      },
    ];
    if (newUser.isAdmin) {
      updates[userList.key({ admin: true })] = (users = []) => [newUserId, ...users];
    }
    return updates;
  },
});
```

</details>


### Entity, EntityRecord, Resource, BaseResource

- Normalizes to pojo
- Faster
- Entity has no defined key lookups - but EntityRecord does.
- BaseResource is missing predefined endpoints (list, detail, etc), but has everything else


### Resource.list() declarative pagination

Addition of `paginated()`.


```ts
class NewsResource extends Resource {
  static listPage<T extends typeof NewsResource>(this: T) {
    return this.list().paginated(({ cursor, ...rest }) => [rest]);
  }
}

```


```tsx
import { useSuspense, useController } from '@rest-hooks/react';
import NewsResource from 'resources/NewsResource';

function NewsList() {
  const { results, cursor } = useSuspense(NewsResource.list(), {});
  const curRef = useRef(cursor);
  curRef.current = cursor;
  const controller = useController();
  const getNextPage = useCallback(
    () => controller.fetch(NewsResource.listPage(), { cursor: curRef.current }),
    []
  );

  return (
    <Pagination onPaginate={getNextPage} nextCursor={cursor}>
      <NewsList data={results} />
    </Pagination>
  );
}
```

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