Experimental extensions for Rest Hooks
npm install @rest-hooks/experimental





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.
``tsx
const controller = useController();
return (
$3
Simple
`typescript
const createUser = new Endpoint(postToUserFunction, {
schema: User,
update: (newUserId: string) => ({
[userList.key({})]: (users = []) => [newUserId, ...users],
}),
});
`Multiple updates
`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;
},
});
`
$3
- 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
$3
Addition of
paginated().
`ts
class NewsResource extends Resource {
static listPage(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 (
);
}
``