@rest-hooks/legacy

Legacy features for Rest Hooks

Usage no npm install needed!

<script type="module">
  import restHooksLegacy from 'https://cdn.skypack.dev/@rest-hooks/legacy';
</script>

README

🛌🎣 Rest Hooks Legacy">

CircleCI Coverage Status npm downloads bundle size npm version PRs Welcome

Rest Hooks without Suspense.

resources/ProfileResource.ts

import { Resource } from '@rest-hooks/legacy';

export default class ProfileResource extends Resource {
  readonly id: number | undefined = undefined;
  readonly img: string = '';
  readonly fullName: string = '';
  readonly bio: string = '';

  pk() {
    return this.id;
  }
  static urlRoot = '/profiles';
}

ProfileList.tsx

import { useStatefulResource } from '@rest-hooks/legacy';
import { Skeleton, Card, Avatar } from 'antd';
import ProfileResource from 'resources/ProfileResource';

const { Meta } = Card;

function ProfileList() {
  const { data, loading, error } = useStatefulResource(
    ProfileResource.detailShape(),
    {},
  );
  if (error) return <div>Error {error.status}</div>
  return (
    <Card style={{ width: 300, marginTop: 16 }} loading={loading}>
      <Meta
        avatar={
          <Avatar src={data.img} />
        }
        title={data.fullName}
        description={data.bio}
      />
    </Card>
  );
}