useResource
Using async resources without tears (and boilerplate)
Demo
Installation
yarn add use-resource-hook
How to use
// Each function should return a promise that returns a `User` when resolves; // `Options` can be passed actions.listapi.users.list; /*When the promise is calledstate => { error: null, action: 'list', resources: [], selected: null} Once is resolvedstate.resources => [{id: "1", name: "Gonzalo", meta: {error: null, action: null}}] On Errorstate => { error: 'Error returned by the server', action: null, resources: [], selected: null}*/ // Also you can use its promiseactions.listapi.users.list.thenactions.selectusers.id; /*state.selected => {id: "1", name: "Gonzalo", meta: {error: null, action: null}}*/
Types
;