rest-hooks
Advanced tools
Comparing version 0.0.9 to 0.0.10
import ModelResource from '../model/ModelResource'; | ||
import { AbstractInstanceType } from '../types'; | ||
export declare function selectResource<T extends typeof ModelResource>(Model: T, selector: (Model: T, state: {}, params: {}) => AbstractInstanceType<T> | null, params: {}): AbstractInstanceType<T> | null; | ||
export declare function fetchResource<T extends typeof ModelResource>(Model: T, params: {}): void; | ||
export declare function useResource<T extends typeof ModelResource>(Model: T, selector: (Model: T, state: {}, params: {}) => AbstractInstanceType<T>, params: {}): AbstractInstanceType<T> | null; | ||
export declare function selectResource<T extends typeof ModelResource>(Model: T, selector: (Model: T, state: {}, params: {}) => AbstractInstanceType<T> | null, params: {} | null): AbstractInstanceType<T> | null; | ||
export declare function fetchResource<T extends typeof ModelResource>(Model: T, params: {} | null): void; | ||
export declare function useResource<T extends typeof ModelResource>(Model: T, selector: (Model: T, state: {}, params: {}) => AbstractInstanceType<T>, params: {} | null): AbstractInstanceType<T> | null; |
@@ -19,3 +19,3 @@ import { useContext, useMemo, useEffect } from 'react'; | ||
var resource = useMemo(function () { | ||
return selector(Model, state, params); | ||
return params && selector(Model, state, params); | ||
}, [state, params]); | ||
@@ -36,6 +36,7 @@ return resource; | ||
useEffect(function () { | ||
if (!params) return; | ||
fetch(Model, params); | ||
return function () {//unsubscribe(Model, params) | ||
}; | ||
}, [Model.url(params)]); | ||
}, [params && Model.url(params)]); | ||
} | ||
@@ -68,2 +69,2 @@ /* | ||
*/ | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb25uZWN0L2hvb2tzLnRzIl0sIm5hbWVzIjpbInVzZUNvbnRleHQiLCJ1c2VNZW1vIiwidXNlRWZmZWN0IiwiU3RhdGVDb250ZXh0IiwiRGlzcGF0Y2hDb250ZXh0Iiwic2VsZWN0UmVzb3VyY2UiLCJNb2RlbCIsInNlbGVjdG9yIiwicGFyYW1zIiwic3RhdGUiLCJ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vZGVsUmVzb3VyY2UpOiBNdXRhdGVEaXNwYXRjaGVycyB7XG5cbn1cbiovXG4iXX0= |
{ | ||
"name": "rest-hooks", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Easy react hooks for REST apis", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
44923
402