Skip to main content
Version: 3.x.x

Effect


Introduction

RequestEffect is basically a set of reducers reacting to the request lifecycle. You can assign it to the Client; its effectKey has to be the same as the request's effect key so you can match it.

The strength of RequestEffect lies in cooperation options with persistent queues. Imagine that you always want to trigger some logic when the request is successful, but you must also use persistent storage to save ongoing requests. But when the app gets relaunched, there is no way to persist functions and logic. Here, the effect is the solution. We can assign it on Client creation so that it will instantly match all ongoing requests from previous sessions.


Purpose

  • Persists request side-effects
  • Manipulates the lifecycle and allows hooking in

EffectKey

A key needed to match the Effect with the request where it's stored. This is automatically generated (like other keys in the request), but you can set up custom values for easier usage and matching.


Parameters

Configuration options

{
effectKey: string;
onError: (response: ResponseReturnErrorType<ExtractErrorType<T>, ExtractAdapterType<T>>, request: RequestInstance) => void;
onFinished: (response: ResponseReturnType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>, request: RequestInstance) => void;
onStart: (request: RequestInstance) => void;
onSuccess: (response: ResponseReturnSuccessType<ExtractResponseType<T>, ExtractAdapterType<T>>, request: RequestInstance) => void;
onTrigger: (request: RequestInstance) => void;
}