Deduplication
In order to limit and optimize the number of queries to the backend
, we can use the feature of deduplication
. We
enable it by setting the deduplicate: true
field on the command options. Thanks to this setting, many requests made
at the same time will be optimized to one request. We can refine the deduplication time with the deduplicateTime
option in the command options.
Setup
export const getUsers = builder.createCommand()({
endpoint: "/users",
deduplicate: true,
});
Example
The example is written in typescript, but it also works in React hooks.
// Multiple calls of the same command
getUsers.send();
getUsers.send();
getUsers.send();
getUsers.send();
// Only single request will be send to backend
To learn more of deduplication
and alternative modes
of requesting you can visit
Dispatcher Docs.