Skip to main content


Describes entities to be marked as INVALID. This removes items from a collection, or forces suspense for endpoints where the entity is required.


  • entity which entity to invalidate. The input is used to compute the pk() for lookup.


GET /users
DELETE /users/:id
import { Entity, RestEndpoint } from '@data-client/rest';

class User extends Entity {
  id = '';
  name = '';
  pk() {
export const getUsers = new RestEndpoint({
  path: '/users',
  schema: new schema.Collection([User]),
export const deleteUser = new RestEndpoint({
  path: '/users/:id',
  method: 'DELETE',
  schema: new schema.Invalidate(User),
import { getUsers, deleteUser } from './api/User';

function UsersPage() {
  const users = useSuspense(getUsers);
  const ctrl = useController();
  return (
      { => (
        <div key={}>
          {}{' '}
            style={{ cursor: 'pointer' }}
            onClick={() => ctrl.fetch(deleteUser, { id: })}

render(<UsersPage />);
🔴 Live Preview

Batch Invalidation

Here we add another endpoint for deleting many entities at a time. Here we pass in a list of ids, and the response is an empty string.

Constructing an article response using the params argument in fetch empowers the normalized cache to know which entities to invalidate when the request is success, or if optimistic updates are used.

import { Resource, schema } from '@data-client/rest';

class MyResource extends Resource {
static deleteList<T extends typeof MyResource>(this: T) {
const init = this.getFetchInit({ method: 'DELETE' });
return new Endpoint(
(params: readonly string[]) =>
this.fetch(this.url(params).then(() => => ({ id })))),
schema: [new schemas.Invalidate(this)],
function MyTable() {
const { selectedIds } = useFields(TableForm);
const list = useSuspense(MyResource.list());
const ctrl = useController();

return (
<span>My Table</span>
<button onClick={() => ctrl.fetch(MyResource.delete, selectedIds)}>
<TableBody data={list} form={TableForm} />

Impact on useSuspense()

When entities are invalidated in a result currently being presented in React, useSuspense() will consider them invalid

  • For optional Entities, they are simply removed
  • For required Entities, this invalidates the entire response re-triggering suspense.