Skip to main content
Version: 4.5

Capturing Mutation Side-Effects

How to deal with side-effects

If you have an endpoint that updates many resources on your server, there is a straightforward mechanism to get all those updates to your client in one request.

By defining a custom FetchShape method on your resource, you'll be able to use custom response shapes that still updated rest-hooks' normalized cache.


You're running a crypto trading platform called dogebase. Every time a user creates a trade, you need to update some balance information in their accounts object. So upon POSTing to the /trade/ endpoint, you nest both the updated accounts object along with the trade you just created.

POST /trade/

"trade": {
"id": 2893232,
"user": 1,
"amount": "50.2335324",
"coin": "doge",
"created_at": ""
"account": {
"id": 899,
"user": 1,
"balance": "1337.00",
"coin_value": "3.50"

To handle this, we just need to update the schema to include the custom shape.


import { Resource } from 'rest-hooks';

class TradeResource extends Resource {
// ...
static createShape<T extends typeof Resource>(this: T) {
return {
schema: {
trade: this.asSchema(),
account: AccountResource.asSchema(),

Now if when we use the createShape() FetchShape generator method, we will be happy knowing both the trade and account information will be updated in the cache after the POST request is complete.


export default function CreateTrade() {
const create = useFetcher(TradeResource.createShape());


Feel free to create completely new FetchShape methods for any custom endpoints you have. This shape tells rest-hooks how to process any request.