@cactuslab/api-helpers
Advanced tools
Comparing version 0.2.0 to 0.2.1
import { DependencyList } from 'react'; | ||
export declare type PromiseEffectResult<T, E> = PromiseEffectResolved<T> | PromiseEffectRejected<E> | PromiseEffectInFlight<T, E>; | ||
interface PromiseEffectResolved<T> { | ||
export declare type PromiseEffectResult<T, E> = PromiseEffectStatus<T, E> & PromiseEffectFunctions<T, E>; | ||
export declare type PromiseEffectStatus<T, E> = PromiseEffectResolved<T> | PromiseEffectRejected<E> | PromiseEffectInFlight<T, E>; | ||
export interface PromiseEffectResolved<T> { | ||
status: 'resolved'; | ||
@@ -8,3 +9,3 @@ result: T; | ||
} | ||
interface PromiseEffectRejected<E> { | ||
export interface PromiseEffectRejected<E> { | ||
status: 'rejected'; | ||
@@ -14,3 +15,3 @@ result?: undefined; | ||
} | ||
interface PromiseEffectInFlight<T, E> { | ||
export interface PromiseEffectInFlight<T, E> { | ||
status: 'inflight'; | ||
@@ -26,3 +27,3 @@ /** | ||
} | ||
interface PromiseEffectFunctions<T, E> { | ||
export interface PromiseEffectFunctions<T, E> { | ||
/** | ||
@@ -41,4 +42,3 @@ * A function that when called triggers the original function to be called again, creating and resolving a new Promise. | ||
*/ | ||
export declare function usePromiseEffect<T, E = unknown>(func: () => () => Promise<T>, deps: DependencyList): PromiseEffectResult<T, E> & PromiseEffectFunctions<T, E>; | ||
export {}; | ||
export declare function usePromiseEffect<T, E = unknown>(func: () => () => Promise<T>, deps: DependencyList): PromiseEffectResult<T, E>; | ||
//# sourceMappingURL=usepromiseeffect.d.ts.map |
{ | ||
"name": "@cactuslab/api-helpers", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Helpers for integrating with a backend API.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { useCallback, useState, useEffect, DependencyList } from 'react' | ||
export type PromiseEffectResult<T, E> = PromiseEffectResolved<T> | PromiseEffectRejected<E> | PromiseEffectInFlight<T, E> | ||
export type PromiseEffectResult<T, E> = PromiseEffectStatus<T, E> & PromiseEffectFunctions<T, E> | ||
interface PromiseEffectResolved<T> { | ||
export type PromiseEffectStatus<T, E> = PromiseEffectResolved<T> | PromiseEffectRejected<E> | PromiseEffectInFlight<T, E> | ||
export interface PromiseEffectResolved<T> { | ||
status: 'resolved' | ||
@@ -11,3 +13,3 @@ result: T | ||
interface PromiseEffectRejected<E> { | ||
export interface PromiseEffectRejected<E> { | ||
status: 'rejected' | ||
@@ -18,3 +20,3 @@ result?: undefined | ||
interface PromiseEffectInFlight<T, E> { | ||
export interface PromiseEffectInFlight<T, E> { | ||
status: 'inflight' | ||
@@ -31,3 +33,3 @@ /** | ||
interface PromiseEffectFunctions<T, E> { | ||
export interface PromiseEffectFunctions<T, E> { | ||
/** | ||
@@ -48,3 +50,3 @@ * A function that when called triggers the original function to be called again, creating and resolving a new Promise. | ||
*/ | ||
export function usePromiseEffect<T, E = unknown>(func: () => () => Promise<T>, deps: DependencyList): PromiseEffectResult<T, E> & PromiseEffectFunctions<T, E> { | ||
export function usePromiseEffect<T, E = unknown>(func: () => () => Promise<T>, deps: DependencyList): PromiseEffectResult<T, E> { | ||
const [version, setVersion] = useState(0) | ||
@@ -54,3 +56,3 @@ | ||
func = useCallback(func, deps) | ||
const [result, setResult] = useState<PromiseEffectResult<T, E>>({ | ||
const [result, setResult] = useState<PromiseEffectStatus<T, E>>({ | ||
status: 'inflight', | ||
@@ -57,0 +59,0 @@ }) |
Sorry, the diff of this file is not supported yet
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
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
37684
697