react-hooks-library
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -8,2 +8,4 @@ export interface IQueryProps<P> { | ||
query?(params?: IQueryProps<P>['variable']): Promise<P>; | ||
onSuccess?(result: P): void; | ||
onFailure?(error: Error): void; | ||
} | ||
@@ -15,5 +17,5 @@ export declare function useQuery<P>(props: IQueryProps<P>): { | ||
error: any; | ||
refetch: (variable?: object | undefined) => Promise<P | undefined>; | ||
refetch: (variable?: object | undefined) => Promise<any>; | ||
startPolling: (interval: number) => void; | ||
stopPolling: () => void; | ||
}; |
@@ -38,27 +38,29 @@ import * as tslib_1 from "tslib"; | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
var response, error_1; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!mergedProps.query) return [3 /*break*/, 2]; | ||
if (!mergedProps.query) return [3 /*break*/, 4]; | ||
setLoading(true); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, mergedProps.query(variable)]; | ||
case 1: | ||
case 2: | ||
response = _a.sent(); | ||
try { | ||
if (response) { | ||
setData(response); | ||
} | ||
else { | ||
reset(); | ||
} | ||
setLoading(false); | ||
return [2 /*return*/, response]; | ||
if (response) { | ||
setData(response); | ||
} | ||
catch (error) { | ||
setError(error); | ||
return [2 /*return*/, response]; | ||
else { | ||
reset(); | ||
} | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, undefined]; | ||
setLoading(false); | ||
typeof props.onSuccess === 'function' && props.onSuccess(response); | ||
return [2 /*return*/, response]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
setError(error_1); | ||
typeof props.onFailure === 'function' && props.onFailure(error_1); | ||
return [2 /*return*/, error_1]; | ||
case 4: return [2 /*return*/, undefined]; | ||
} | ||
@@ -65,0 +67,0 @@ }); |
{ | ||
"name": "react-hooks-library", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -13,2 +13,4 @@ import { useState, useEffect } from 'react' | ||
query?(params?: IQueryProps<P>['variable']): Promise<P> | ||
onSuccess?(result: P): void | ||
onFailure?(error: Error): void | ||
} | ||
@@ -56,5 +58,5 @@ | ||
const response = await mergedProps.query(variable) | ||
try { | ||
const response = await mergedProps.query(variable) | ||
try { | ||
if (response) { | ||
@@ -67,2 +69,3 @@ setData(response) | ||
setLoading(false) | ||
typeof props.onSuccess === 'function' && props.onSuccess(response) | ||
@@ -73,3 +76,5 @@ return response | ||
return response | ||
typeof props.onFailure === 'function' && props.onFailure(error) | ||
return error | ||
} | ||
@@ -76,0 +81,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
react-hooks-testing-library |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
303603
2020
0