8.2.2 • Published 9 months ago

@rest-hooks/react v8.2.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

🛌🎣 Rest hooks

CircleCI Coverage Status npm downloads bundle size npm version PRs Welcome

Define your async methods. Use them synchronously in React. Instantly mutate the data and automatically update all usages.

For REST, GraphQL, Websockets+SSE and more

📖Read The Docs  |  🏁Getting Started  |  🎮Todo Demo  |  🎮Github Demo  |  🎮NextJS SSR Demo

Installation

npm install @rest-hooks/react @rest-hooks/rest @rest-hooks/test

For more details, see the Installation docs page.

Simple TypeScript definition

class Article extends Entity {
  id = '';
  title = '';
  body = '';

  pk() {
    return this.id;
  }
}

Create collection of API Endpoints

const ArticleResource = createResource({
  path: '/articles/:id',
  schema: Article,
})

One line data binding

const article = useSuspense(ArticleResource.get, { id });
return (
  <>
    <h2>{article.title}</h2>
    <p>{article.body}</p>
  </>
);

Mutation

const ctrl = useController();
return (
  <ArticleForm
    onSubmit={data => ctrl.fetch(ArticleResource.update, { id }, data)}
  />
);

Subscriptions

const price = useLive(PriceResource.get, { symbol });
return price.value;

Programmatic queries

const sortedArticles = new Query(
  new schema.All(Article),
  (entries, { asc } = { asc: false }) => {
    const sorted = [...entries].sort((a, b) => a.title.localeCompare(b.title));
    if (asc) return sorted;
    return sorted.reverse();
  }
);

const articlesUnsorted = useCache(sortedArticles);
const articlesAscending = useCache(sortedArticles, { asc: true });
const articlesDescending = useCache(sortedArticles, { asc: false });

...all typed ...fast ...and consistent

For the small price of 9kb gziped.    🏁Get started now | 🥊Comparison

Features

Examples

8.2.2

9 months ago

7.4.3

10 months ago

8.1.0

9 months ago

8.0.0

10 months ago

8.2.1

9 months ago

8.2.0

9 months ago

6.2.0

11 months ago

7.4.0

1 year ago

7.4.2

11 months ago

7.4.1

1 year ago

6.1.0

1 year ago

7.4.0-next.0

1 year ago

7.3.1

1 year ago

7.3.0

1 year ago

7.2.6

1 year ago

7.2.5

1 year ago

7.2.9

1 year ago

7.2.8

1 year ago

7.2.7

1 year ago

7.2.12

1 year ago

7.2.11

1 year ago

7.2.10

1 year ago

7.2.4

1 year ago

7.2.3

1 year ago

7.2.2

1 year ago

7.2.1

1 year ago

7.2.0

1 year ago

7.1.7

1 year ago

7.1.6

1 year ago

7.1.5

1 year ago

7.1.4

1 year ago

6.0.1

1 year ago

7.1.3

1 year ago

7.1.2

1 year ago

7.1.1

1 year ago

7.1.0

1 year ago

7.1.0-beta.0

1 year ago

7.0.0

1 year ago

6.0.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago