createResource
Last updated
Last updated
Creates a resource and associated actions and selectors to interact with it
(resourceName): (string
) The name under which the resource will be stored in the state
(options): (object
) An object containing additional, optional options for the resource:
A. (cacheLifetime): (number
, default: 0) The duration (in seconds) for which the resource will be considered valid (from 0
- no cache - to Infinity
- cached permanently)
B. (denormalizer): ((resourceIds, resources) : array<resources>
, default null) A function useful to denormalize nested objects which have been normalized by actionName.normalizer
(e.g. via )
(actions): (map<actionName:config>
) An object of configs with the following attributes:
This example demonstrates how to use createResource
to create a sample resource, and then to export the reducers, actions and selectors.
The above example is very exhaustive, but you can export only what you really need
Naming is a matter of personal preference, use what works for you
You can alternately just export users
, and spare yourself the trouble of mapping the names. Then just use the selectors like so: users.selectors.resource.getResource()
. Again, use what works for you
Extensive documentation on actions configuration can be found .
(Object): An object containing and .