createResource
Creates a resource and associated actions and selectors to interact with it
Arguments
(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 (from0
- no cache - toInfinity
- cached permanently)B. (denormalizer): (
(resourceIds, resources) : array<resources>
, default null) A function useful to denormalize nested objects which have been normalized byactionName.normalizer
(e.g. via normalizr)(actions): (
map<actionName:config>
) An object of configs with the following attributes:
Extensive documentation on actions configuration can be found here.
Returns
(Object): An object containing actions and selectors.
Example
This example demonstrates how to use createResource
to create a sample resource, and then to export the reducers, actions and selectors.
Tips
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
Last updated