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

fenextjs-hook

Package Overview
Dependencies
Maintainers
1
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fenextjs-hook - npm Package Compare versions

Comparing version 1.2.35 to 1.2.36

9

cjs/useRequest.d.ts

@@ -27,1 +27,10 @@ import { RequestProps, RequestResultDataProps, RequestResultTypeProps } from "fenextjs-interface/cjs/Request";

};
export interface useRequestFunctionProps<FP, FR> {
f: RequestProps<FP, FR>;
}
export declare const useRequestFunction: <FP = any, FR = any>({ f, }: useRequestFunctionProps<FP, FR>) => {
loader: boolean;
error: undefined;
result: FR | undefined;
onRequest: (props: FP) => Promise<any>;
};

34

cjs/useRequest.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useRequest = void 0;
exports.useRequestFunction = exports.useRequest = void 0;
const react_1 = require("react");

@@ -45,2 +45,34 @@ /**

exports.useRequest = useRequest;
const useRequestFunction = ({ f, }) => {
const [loader, setLoader] = (0, react_1.useState)(false);
const [error, setError] = (0, react_1.useState)(undefined);
const [result, setResult] = (0, react_1.useState)(undefined);
const onRequest = async (props) => {
setLoader(true);
setError(undefined);
setResult(undefined);
try {
const r = await f(props);
if (r.error) {
throw r.error;
}
setResult(r.result);
return r;
}
catch (error) {
setError(error);
return error;
}
finally {
setLoader(false);
}
};
return {
loader,
error,
result,
onRequest,
};
};
exports.useRequestFunction = useRequestFunction;
//# sourceMappingURL=useRequest.js.map

@@ -27,1 +27,10 @@ import { RequestProps, RequestResultDataProps, RequestResultTypeProps } from "fenextjs-interface/cjs/Request";

};
export interface useRequestFunctionProps<FP, FR> {
f: RequestProps<FP, FR>;
}
export declare const useRequestFunction: <FP = any, FR = any>({ f, }: useRequestFunctionProps<FP, FR>) => {
loader: boolean;
error: undefined;
result: FR | undefined;
onRequest: (props: FP) => Promise<any>;
};

@@ -41,2 +41,33 @@ import { useCallback, useEffect, useState } from "react";

};
export const useRequestFunction = ({ f, }) => {
const [loader, setLoader] = useState(false);
const [error, setError] = useState(undefined);
const [result, setResult] = useState(undefined);
const onRequest = async (props) => {
setLoader(true);
setError(undefined);
setResult(undefined);
try {
const r = await f(props);
if (r.error) {
throw r.error;
}
setResult(r.result);
return r;
}
catch (error) {
setError(error);
return error;
}
finally {
setLoader(false);
}
};
return {
loader,
error,
result,
onRequest,
};
};
//# sourceMappingURL=useRequest.js.map

2

package.json
{
"name": "fenextjs-hook",
"version": "1.2.35",
"version": "1.2.36",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js",

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