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

react-async-hook

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-async-hook - npm Package Compare versions

Comparing version 3.5.1 to 3.5.2

15

dist/index.d.ts

@@ -1,2 +0,3 @@

declare type UnknownArgs = unknown[];
declare type UnknownResult = unknown;
declare type UnknownArgs = any[];
export declare type AsyncStateStatus = 'not-requested' | 'loading' | 'success' | 'error';

@@ -27,3 +28,3 @@ export declare type AsyncState<R> = {

export declare type UseAsyncOptions<R> = Partial<UseAsyncOptionsNormalized<R>> | undefined | null;
export declare type UseAsyncReturn<R, Args extends any[] = UnknownArgs> = AsyncState<R> & {
export declare type UseAsyncReturn<R = UnknownResult, Args extends any[] = UnknownArgs> = AsyncState<R> & {
set: (value: AsyncState<R>) => void;

@@ -35,7 +36,9 @@ reset: () => void;

};
export declare function useAsync<R, Args extends any[] = UnknownArgs>(asyncFunction: () => Promise<R>, params: Args, options?: UseAsyncOptions<R>): UseAsyncReturn<R, Args>;
export declare function useAsync<R, Args extends any[] = UnknownArgs>(asyncFunction: (...args: Args) => Promise<R>, params: Args, options?: UseAsyncOptions<R>): UseAsyncReturn<R, Args>;
export declare function useAsync<R = UnknownResult, Args extends any[] = UnknownArgs>(asyncFunction: () => Promise<R>, params: Args, options?: UseAsyncOptions<R>): UseAsyncReturn<R, Args>;
export declare function useAsync<R = UnknownResult, Args extends any[] = UnknownArgs>(asyncFunction: (...args: Args) => Promise<R>, params: Args, options?: UseAsyncOptions<R>): UseAsyncReturn<R, Args>;
declare type AddArg<H, T extends any[]> = ((h: H, ...t: T) => void) extends ((...r: infer R) => void) ? R : never;
export declare const useAsyncAbortable: <R, Args extends any[] = unknown[]>(asyncFunction: (...args: AddArg<AbortSignal, Args>) => Promise<R>, params: Args, options?: UseAsyncOptions<R>) => UseAsyncReturn<R, Args>;
export declare const useAsyncCallback: <R, Args extends any[] = unknown[]>(asyncFunction: (...args: Args) => MaybePromise<R>) => UseAsyncReturn<R, Args>;
export declare const useAsyncAbortable: <R = unknown, Args extends any[] = any[]>(asyncFunction: (...args: AddArg<AbortSignal, Args>) => Promise<R>, params: Args, options?: UseAsyncOptions<R>) => UseAsyncReturn<R, Args>;
declare type LegacyOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export declare type UseAsyncCallbackOptions<R> = LegacyOmit<Partial<UseAsyncOptionsNormalized<R>>, 'executeOnMount' | 'executeOnUpdate' | 'initialState'> | undefined | null;
export declare const useAsyncCallback: <R = unknown, Args extends any[] = any[]>(asyncFunction: (...args: Args) => MaybePromise<R>, options?: UseAsyncCallbackOptions<R>) => UseAsyncReturn<R, Args>;
export {};

6

dist/react-async-hook.cjs.development.js

@@ -272,9 +272,9 @@ 'use strict';

};
var useAsyncCallback = function useAsyncCallback(asyncFunction) {
var useAsyncCallback = function useAsyncCallback(asyncFunction, options) {
return useAsyncInternal(asyncFunction, // Hacky but in such case we don't need the params,
// because async function is only executed manually
[], {
[], _extends({}, options, {
executeOnMount: false,
executeOnUpdate: false
});
}));
};

@@ -281,0 +281,0 @@

@@ -1,2 +0,2 @@

"use strict";var r=require("react");function t(){return(t=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var e={status:"not-requested",loading:!1,result:void 0,error:void 0},n={status:"loading",loading:!0,result:void 0,error:void 0},u=function(){},o={initialState:function(r){return r&&r.executeOnMount?n:e},executeOnMount:!0,executeOnUpdate:!0,setLoading:function(r){return n},setResult:function(r,t){return{status:"success",loading:!1,result:r,error:void 0}},setError:function(r,t){return{status:"error",loading:!1,result:void 0,error:r}},onSuccess:u,onError:u},i=function(e,n,u){var i,s=function(r){return t({},o,{},r)}(u),c=r.useState(null),a=c[0],l=c[1],f=function(t){var e=r.useState(function(){return t.initialState(t)}),n=e[0],u=e[1],o=r.useCallback(function(){return u(t.initialState(t))},[u,t]),i=r.useCallback(function(){return u(t.setLoading(n))},[n,u]),s=r.useCallback(function(r){return u(t.setResult(r,n))},[n,u]),c=r.useCallback(function(r){return u(t.setError(r,n))},[n,u]);return{value:n,set:u,reset:o,setLoading:i,setResult:s,setError:c}}(s),v=(i=r.useRef(!1),r.useEffect(function(){return i.current=!0,function(){i.current=!1}},[]),function(){return i.current}),d=function(){var t=r.useRef(null);return{set:function(r){return t.current=r},get:function(){return t.current},is:function(r){return t.current===r}}}(),y=function(r){return v()&&d.is(r)},b=function(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];var u=e.apply(void 0,t);if(l(t),u instanceof Promise)return d.set(u),f.setLoading(),u.then(function(r){y(u)&&f.setResult(r),s.onSuccess(r,{isCurrent:function(){return d.is(u)}})},function(r){y(u)&&f.setError(r),s.onError(r,{isCurrent:function(){return d.is(u)}})}),u;var o=u;return f.setResult(o),Promise.resolve(o)},p=!v();return r.useEffect(function(){p?(s.executeOnMount&&b.apply(void 0,n),s.executeOnMount&&b.apply(void 0,n)):s.executeOnUpdate&&b.apply(void 0,n)},n),t({},f.value,{set:f.set,reset:f.reset,execute:b,currentPromise:d.get(),currentParams:a})};function s(r,t,e){return i(r,t,e)}exports.useAsync=s,exports.useAsyncAbortable=function(t,e,n){var u=r.useRef();return s(function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];try{u.current&&u.current.abort();var o=new AbortController;return u.current=o,Promise.resolve(function(r,n){try{var u=Promise.resolve(t.apply(void 0,[o.signal].concat(e)))}catch(r){return n(!0,r)}return u&&u.then?u.then(n.bind(null,!1),n.bind(null,!0)):n(!1,value)}(0,function(r,t){if(u.current===o&&(u.current=void 0),r)throw t;return t}))}catch(r){return Promise.reject(r)}},e,n)},exports.useAsyncCallback=function(r){return i(r,[],{executeOnMount:!1,executeOnUpdate:!1})};
"use strict";var r=require("react");function t(){return(t=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var e={status:"not-requested",loading:!1,result:void 0,error:void 0},n={status:"loading",loading:!0,result:void 0,error:void 0},u=function(){},o={initialState:function(r){return r&&r.executeOnMount?n:e},executeOnMount:!0,executeOnUpdate:!0,setLoading:function(r){return n},setResult:function(r,t){return{status:"success",loading:!1,result:r,error:void 0}},setError:function(r,t){return{status:"error",loading:!1,result:void 0,error:r}},onSuccess:u,onError:u},i=function(e,n,u){var i,s=function(r){return t({},o,{},r)}(u),c=r.useState(null),a=c[0],l=c[1],f=function(t){var e=r.useState(function(){return t.initialState(t)}),n=e[0],u=e[1],o=r.useCallback(function(){return u(t.initialState(t))},[u,t]),i=r.useCallback(function(){return u(t.setLoading(n))},[n,u]),s=r.useCallback(function(r){return u(t.setResult(r,n))},[n,u]),c=r.useCallback(function(r){return u(t.setError(r,n))},[n,u]);return{value:n,set:u,reset:o,setLoading:i,setResult:s,setError:c}}(s),v=(i=r.useRef(!1),r.useEffect(function(){return i.current=!0,function(){i.current=!1}},[]),function(){return i.current}),d=function(){var t=r.useRef(null);return{set:function(r){return t.current=r},get:function(){return t.current},is:function(r){return t.current===r}}}(),y=function(r){return v()&&d.is(r)},b=function(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];var u=e.apply(void 0,t);if(l(t),u instanceof Promise)return d.set(u),f.setLoading(),u.then(function(r){y(u)&&f.setResult(r),s.onSuccess(r,{isCurrent:function(){return d.is(u)}})},function(r){y(u)&&f.setError(r),s.onError(r,{isCurrent:function(){return d.is(u)}})}),u;var o=u;return f.setResult(o),Promise.resolve(o)},p=!v();return r.useEffect(function(){p?(s.executeOnMount&&b.apply(void 0,n),s.executeOnMount&&b.apply(void 0,n)):s.executeOnUpdate&&b.apply(void 0,n)},n),t({},f.value,{set:f.set,reset:f.reset,execute:b,currentPromise:d.get(),currentParams:a})};function s(r,t,e){return i(r,t,e)}exports.useAsync=s,exports.useAsyncAbortable=function(t,e,n){var u=r.useRef();return s(function(){for(var r=arguments.length,e=new Array(r),n=0;n<r;n++)e[n]=arguments[n];try{u.current&&u.current.abort();var o=new AbortController;return u.current=o,Promise.resolve(function(r,n){try{var u=Promise.resolve(t.apply(void 0,[o.signal].concat(e)))}catch(r){return n(!0,r)}return u&&u.then?u.then(n.bind(null,!1),n.bind(null,!0)):n(!1,value)}(0,function(r,t){if(u.current===o&&(u.current=void 0),r)throw t;return t}))}catch(r){return Promise.reject(r)}},e,n)},exports.useAsyncCallback=function(r,e){return i(r,[],t({},e,{executeOnMount:!1,executeOnUpdate:!1}))};
//# sourceMappingURL=react-async-hook.cjs.production.min.js.map

@@ -270,9 +270,9 @@ import { useRef, useState, useEffect, useCallback } from 'react';

};
var useAsyncCallback = function useAsyncCallback(asyncFunction) {
var useAsyncCallback = function useAsyncCallback(asyncFunction, options) {
return useAsyncInternal(asyncFunction, // Hacky but in such case we don't need the params,
// because async function is only executed manually
[], {
[], _extends({}, options, {
executeOnMount: false,
executeOnUpdate: false
});
}));
};

@@ -279,0 +279,0 @@

{
"name": "react-async-hook",
"version": "3.5.1",
"version": "3.5.2",
"description": "Async hook",

@@ -5,0 +5,0 @@ "author": "Sébastien Lorber",

Sorry, the diff of this file is not supported yet

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