Skip to content

Instantly share code, notes, and snippets.

@mattpocock
Last active May 31, 2019 12:45
Show Gist options
  • Save mattpocock/27ff4201e04517609031552cca7d818c to your computer and use it in GitHub Desktop.
Save mattpocock/27ff4201e04517609031552cca7d818c to your computer and use it in GitHub Desktop.
/** Account manager becomes a wrapped instance of the api which you can perform actions on */
const accountManager = useResource('AccountManagerResource');
/** 'fetch' calls will first check the cache, then return it to the data prop */
accountManager.fetch({ ...params });
accountManager.fetchAll({ ...params });
/** refetch calls will override the cache */
accountManager.refetch({ ...params });
accountManager.refetchAll({ ...params });
/** clear the cache like so: */
accountManager.clearCache();
/** On success, CUD operations will delete the cache */
accountManager.create({ ...params });
accountManager.update({ ...params });
accountManager.deleteById(1);
accountManager.state.loaded;
accountManager.state.errored;
accountManager.state.succeeded;
accountManager.state.data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment