actions
Last updated
Last updated
Creating a resource with will return an object containing an actions
key, with the following properties:
These functions can be imported in components and directly dispatched.
resource.invalidate
and resource.invalidateId
respectively invalidate the requests performed on the related resource and resource id.
resource.reset
removes resources and requests linked to the resource from your state.
actionName.invalidate
invalidates the related request.
actionName.perform
performs the request, accepting the following object as an argument:
(query): (map<queryParam:value>
) An object to prepend a query to the URL
(body): (map<bodyParam:value>
) An object to specify the body of the request (e.g. POST)
(onSuccess): ((normalizedPayload, otherArgs) : undefined
) A hook which will be invoked after the request has performed successfully. Useful to update the UI accordingly, at the component level
(onFailure): ((error) : undefined
) A hook which will be invoked when the request fails. Useful to update the UI accordingly, at the component level
(...otherArgs): (any
) You can also pass any other args you may need in beforeHook
, normalizer
, metadataNormalizer
, afterHook
, and onSuccess
. They will be forwarded to these functions, as an object
This example demonstrates a sample call to an action
.
(urlParams): (map<urlParam:value>
) An object to replace dynamic parameters in the URL (see )