Refresh a resource()

Keeping a resource() up to date after a write, the simple way: onSuccess calls users.reload(). The server stays the source of truth, and the new user appears once the list is fetched again. Source

  • Ada Lovelace
  • Grace Hopper

A create takes 2 s, a fetch 0.8 s (artificial delays).

Server

  1. 8:59:27 AM: fetchUsers() done
  2. 8:59:26 AM: fetchUsers() received
protected readonly createUser = mutation<string, User, Error>({
  mutationFn: (name, abortSignal) => this.server.createUser(name, abortSignal),
  onSuccess: () => this.users.reload(),
});