Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hooks-library

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-library - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

13

dist/hooks/useQuery.d.ts

@@ -1,15 +0,16 @@

export interface IQueryProps {
export interface IQueryProps<P> {
initialData?: P;
variable?: object;
pollInterval?: number;
skip?: boolean;
query?(params?: object): Promise<any>;
query?(params?: object): Promise<P>;
}
export declare function useQuery(props: IQueryProps): {
data: undefined;
export declare function useQuery<P>(props: IQueryProps<P>): {
data: P | undefined;
clear: () => void;
loading: boolean;
error: undefined;
refetch: () => Promise<any>;
error: any;
refetch: () => Promise<P | undefined>;
startPolling: (interval: number) => void;
stopPolling: () => void;
};

@@ -8,3 +8,3 @@ import * as tslib_1 from "tslib";

var _this = this;
var _a = useState(undefined), data = _a[0], setData = _a[1];
var _a = useState(props.initialData), data = _a[0], setData = _a[1];
var _b = useState(undefined), error = _b[0], setError = _b[1];

@@ -25,34 +25,33 @@ var _c = useState(false), loading = _c[0], setLoading = _c[1];

var queryTransaction = function (skip) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var query, response, error_1;
var response;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(!skip && props.query)) return [3 /*break*/, 4];
if (!(!skip && props.query)) return [3 /*break*/, 2];
setLoading(true);
query = props.query(props.variable);
_a.label = 1;
return [4 /*yield*/, props.query(props.variable)];
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, query];
case 2:
response = _a.sent();
if (response) {
if (response.defintions) {
setData(tslib_1.__assign({}, response, { data: decorateModel(response.data, response.defintions) }));
try {
if (response) {
if (response['defintions']) {
setData(tslib_1.__assign({}, response, { data: decorateModel(response['data'], response['defintions']) }));
}
else {
setData(response);
}
setLoading(false);
}
else {
setData(response);
clear();
setLoading(false);
}
setLoading(false);
return [2 /*return*/, response];
}
else {
clear();
setLoading(false);
catch (error) {
setError(error);
return [2 /*return*/, response];
}
return [2 /*return*/, response];
case 3:
error_1 = _a.sent();
setError(error_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
_a.label = 2;
case 2: return [2 /*return*/, undefined];
}

@@ -59,0 +58,0 @@ });

{
"name": "react-hooks-library",
"version": "0.0.3",
"version": "0.0.4",
"license": "MIT",

@@ -13,2 +13,3 @@ "scripts": {

"module": "dist/index.js",
"typings": "index.d.ts",
"devDependencies": {

@@ -15,0 +16,0 @@ "@babel/core": "^7.2.2",

@@ -7,12 +7,13 @@ import { useState, useEffect } from 'react'

export interface IQueryProps {
export interface IQueryProps<P> {
initialData?: P
variable?: object
pollInterval?: number
skip?: boolean
query?(params?: object): Promise<any>
query?(params?: object): Promise<P>
}
export function useQuery(props: IQueryProps) {
const [data, setData] = useState(undefined)
const [error, setError] = useState(undefined)
export function useQuery<P>(props: IQueryProps<P>) {
const [data, setData] = useState<P | undefined>(props.initialData)
const [error, setError] = useState<any>(undefined)
const [loading, setLoading] = useState(false)

@@ -42,12 +43,10 @@ const [intervalIndex, setIntervalIndex] = useState<number | undefined>(

const query = props.query(props.variable)
const response = await props.query(props.variable)
try {
const response = await query
if (response) {
if (response.defintions) {
if (response['defintions']) {
setData({
...response,
data: decorateModel(response.data, response.defintions),
data: decorateModel(response['data'], response['defintions']),
})

@@ -68,4 +67,8 @@ } else {

setError(error)
return response
}
}
return undefined
}

@@ -72,0 +75,0 @@ const refetch = () => queryTransaction(false)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc