@axios-use/react
Advanced tools
Comparing version 6.0.0 to 6.1.0
@@ -0,1 +1,26 @@ | ||
## [6.1.0](https://github.com/axios-use/react/compare/v6.0.0...v6.1.0) (2022-07-05) | ||
### Features | ||
* feat(useRequest): return all response. ([e9317ce](https://github.com/axios-use/react/commit/e9317ce246a0c286c6e548d2f153dbc2cd8411b6)) | ||
```diff | ||
interface CreateRequest { | ||
// Promise function | ||
- ready: () => Promise<[Payload<TRequest>, AxiosRestResponse]>; | ||
+ ready: () => Promise<[Payload<TRequest>, AxiosResponse]>; | ||
// Axios Canceler. clear current request. | ||
cancel: Canceler; | ||
} | ||
``` | ||
```diff | ||
- const [{ data, error, isLoading, other }] = useResource(...) | ||
+ const [{ data, error, isLoading, response }] = useResource(...) | ||
``` | ||
No BREAKING CHANGES. Will keep `other` value, but deprecated. | ||
# [6.0.0](https://github.com/axios-use/react/compare/v5.1.0...v6.0.0) (2022-05-15) | ||
@@ -2,0 +27,0 @@ |
import type { AxiosRequestConfig, AxiosResponse, AxiosError, Canceler } from "axios"; | ||
/** @deprecated No longer use. Use `AxiosResponse` instead */ | ||
export declare type AxiosRestResponse<D = any> = Omit<AxiosResponse<unknown, D>, "data">; | ||
@@ -14,3 +15,3 @@ export interface Resource<TPayload, D = any> extends AxiosRequestConfig<D> { | ||
Payload<TRequest>, | ||
AxiosRestResponse<CData<TRequest>> | ||
AxiosResponse<unknown, CData<TRequest>> | ||
]>; | ||
@@ -30,3 +31,3 @@ }; | ||
export declare type RequestCallbackFn<TRequest extends Request> = { | ||
onCompleted?: (data?: Payload<TRequest>, other?: AxiosRestResponse<CData<TRequest>>) => void; | ||
onCompleted?: (data?: Payload<TRequest>, response?: AxiosResponse<CData<TRequest>>) => void; | ||
onError?: (err?: RequestError<Payload<TRequest>, CData<TRequest>>) => void; | ||
@@ -33,0 +34,0 @@ }; |
@@ -12,13 +12,2 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -71,5 +60,4 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
removeCancelToken(source.token); | ||
var data = response.data, restResponse = __rest(response, ["data"]); | ||
(_a = onCompletedRef.current) === null || _a === void 0 ? void 0 : _a.call(onCompletedRef, data, restResponse); | ||
return [data, restResponse]; | ||
(_a = onCompletedRef.current) === null || _a === void 0 ? void 0 : _a.call(onCompletedRef, response.data, response); | ||
return [response.data, response]; | ||
}) | ||
@@ -76,0 +64,0 @@ .catch(function (err) { |
@@ -1,3 +0,3 @@ | ||
import type { Canceler } from "axios"; | ||
import type { Payload, CData, RequestError, Request, RequestDispatcher, RequestCallbackFn, AxiosRestResponse } from "./request"; | ||
import type { Canceler, AxiosResponse } from "axios"; | ||
import type { Payload, CData, RequestError, Request, RequestDispatcher, RequestCallbackFn } from "./request"; | ||
import type { RequestContextConfig } from "./requestContext"; | ||
@@ -7,5 +7,7 @@ import type { CacheKey, CacheKeyFn } from "./cache"; | ||
data?: Payload<TRequest>; | ||
other?: AxiosRestResponse<CData<TRequest>>; | ||
response?: AxiosResponse<CData<TRequest>>; | ||
error?: RequestError<Payload<TRequest>, CData<TRequest>>; | ||
isLoading?: boolean; | ||
/** @deprecated Use `response` instead */ | ||
other?: AxiosResponse<CData<TRequest>>; | ||
}; | ||
@@ -12,0 +14,0 @@ export declare type UseResourceResult<TRequest extends Request> = [ |
@@ -63,7 +63,10 @@ var __assign = (this && this.__assign) || function () { | ||
function getNextState(state, action) { | ||
var response = action.type === "success" ? action.response : state.response; | ||
return { | ||
data: action.type === "success" ? action.data : state.data, | ||
other: action.type === "success" ? action.other : state.other, | ||
response: response, | ||
error: action.type === "error" ? action.error : undefined, | ||
isLoading: action.type === "start" ? true : false, | ||
// will be deleted | ||
other: response, | ||
}; | ||
@@ -124,3 +127,3 @@ } | ||
void (function () { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, data, other, e_1, error; | ||
var _a, data, response, e_1, error; | ||
return __generator(this, function (_b) { | ||
@@ -133,5 +136,5 @@ switch (_b.label) { | ||
case 1: | ||
_a = _b.sent(), data = _a[0], other = _a[1]; | ||
_a = _b.sent(), data = _a[0], response = _a[1]; | ||
if (getMountedState()) { | ||
dispatch({ type: "success", data: data, other: other }); | ||
dispatch({ type: "success", data: data, response: response }); | ||
cacheKey && | ||
@@ -138,0 +141,0 @@ requestCache && |
import type { AxiosRequestConfig, AxiosResponse, AxiosError, Canceler } from "axios"; | ||
/** @deprecated No longer use. Use `AxiosResponse` instead */ | ||
export declare type AxiosRestResponse<D = any> = Omit<AxiosResponse<unknown, D>, "data">; | ||
@@ -14,3 +15,3 @@ export interface Resource<TPayload, D = any> extends AxiosRequestConfig<D> { | ||
Payload<TRequest>, | ||
AxiosRestResponse<CData<TRequest>> | ||
AxiosResponse<unknown, CData<TRequest>> | ||
]>; | ||
@@ -30,3 +31,3 @@ }; | ||
export declare type RequestCallbackFn<TRequest extends Request> = { | ||
onCompleted?: (data?: Payload<TRequest>, other?: AxiosRestResponse<CData<TRequest>>) => void; | ||
onCompleted?: (data?: Payload<TRequest>, response?: AxiosResponse<CData<TRequest>>) => void; | ||
onError?: (err?: RequestError<Payload<TRequest>, CData<TRequest>>) => void; | ||
@@ -33,0 +34,0 @@ }; |
@@ -13,13 +13,2 @@ "use strict"; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -77,5 +66,4 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
removeCancelToken(source.token); | ||
var data = response.data, restResponse = __rest(response, ["data"]); | ||
(_a = onCompletedRef.current) === null || _a === void 0 ? void 0 : _a.call(onCompletedRef, data, restResponse); | ||
return [data, restResponse]; | ||
(_a = onCompletedRef.current) === null || _a === void 0 ? void 0 : _a.call(onCompletedRef, response.data, response); | ||
return [response.data, response]; | ||
}) | ||
@@ -82,0 +70,0 @@ .catch(function (err) { |
@@ -1,3 +0,3 @@ | ||
import type { Canceler } from "axios"; | ||
import type { Payload, CData, RequestError, Request, RequestDispatcher, RequestCallbackFn, AxiosRestResponse } from "./request"; | ||
import type { Canceler, AxiosResponse } from "axios"; | ||
import type { Payload, CData, RequestError, Request, RequestDispatcher, RequestCallbackFn } from "./request"; | ||
import type { RequestContextConfig } from "./requestContext"; | ||
@@ -7,5 +7,7 @@ import type { CacheKey, CacheKeyFn } from "./cache"; | ||
data?: Payload<TRequest>; | ||
other?: AxiosRestResponse<CData<TRequest>>; | ||
response?: AxiosResponse<CData<TRequest>>; | ||
error?: RequestError<Payload<TRequest>, CData<TRequest>>; | ||
isLoading?: boolean; | ||
/** @deprecated Use `response` instead */ | ||
other?: AxiosResponse<CData<TRequest>>; | ||
}; | ||
@@ -12,0 +14,0 @@ export declare type UseResourceResult<TRequest extends Request> = [ |
@@ -66,7 +66,10 @@ "use strict"; | ||
function getNextState(state, action) { | ||
var response = action.type === "success" ? action.response : state.response; | ||
return { | ||
data: action.type === "success" ? action.data : state.data, | ||
other: action.type === "success" ? action.other : state.other, | ||
response: response, | ||
error: action.type === "error" ? action.error : undefined, | ||
isLoading: action.type === "start" ? true : false, | ||
// will be deleted | ||
other: response, | ||
}; | ||
@@ -127,3 +130,3 @@ } | ||
void (function () { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, data, other, e_1, error; | ||
var _a, data, response, e_1, error; | ||
return __generator(this, function (_b) { | ||
@@ -136,5 +139,5 @@ switch (_b.label) { | ||
case 1: | ||
_a = _b.sent(), data = _a[0], other = _a[1]; | ||
_a = _b.sent(), data = _a[0], response = _a[1]; | ||
if (getMountedState()) { | ||
dispatch({ type: "success", data: data, other: other }); | ||
dispatch({ type: "success", data: data, response: response }); | ||
cacheKey && | ||
@@ -141,0 +144,0 @@ requestCache && |
{ | ||
"name": "@axios-use/react", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "A React hook plugin for Axios. Lightweight, cancelable and less change", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -17,2 +17,3 @@ English | [简体中文](./README.zh-CN.md) | ||
<a href="https://www.npmjs.com/package/@axios-use/react" target="__blank"><img src="https://img.shields.io/npm/v/@axios-use/react.svg" alt="NPM version"></a> | ||
<a href="https://www.npmjs.com/package/@react-cmpt/react-request-hook" target="__blank"><img src="https://img.shields.io/badge/old%20version-v5.1.0-inactive.svg" alt="NPM old version"></a> | ||
<a href="https://github.com/axios-use/react/actions?query=workflow%3ACI" target="__blank"><img src="https://github.com/axios-use/react/workflows/CI/badge.svg" alt="ci"></a> | ||
@@ -109,3 +110,3 @@ <a href="https://github.com/axios-use/react/blob/main/LICENSE" target="__blank"><img src="https://img.shields.io/github/license/axios-use/react" alt="license"></a> | ||
// Promise function | ||
ready: () => Promise<[Payload<TRequest>, AxiosRestResponse]>; | ||
ready: () => Promise<[Payload<TRequest>, AxiosResponse]>; | ||
// Axios Canceler. clear current request. | ||
@@ -143,3 +144,3 @@ cancel: Canceler; | ||
{ | ||
onCompleted: (data, other) => console.info(data, other), | ||
onCompleted: (data, response) => console.info(data, response), | ||
onError: (err) => console.info(err), | ||
@@ -160,3 +161,3 @@ }, | ||
| options.filter | function | Request filter. if return a falsy value, will not start the request | | ||
| options.defaultState | object | Initialize the state value. `{data, other, error, isLoading}` | | ||
| options.defaultState | object | Initialize the state value. `{data, response, error, isLoading}` | | ||
| options.onCompleted | function | This function is passed the query's result data. | | ||
@@ -187,4 +188,4 @@ | options.onError | function | This function is passed an `RequestError` object | | ||
data?: Payload<TRequest>; | ||
// other axios response. Omit<AxiosResponse, "data"> | ||
other?: AxiosRestResponse; | ||
// axios response | ||
response?: AxiosResponse; | ||
// normalized error | ||
@@ -243,3 +244,3 @@ error?: RequestError<Payload<TRequest>>; | ||
{ | ||
onCompleted: (data, other) => console.info(data, other), | ||
onCompleted: (data, response) => console.info(data, response), | ||
onError: (err) => console.info(err), | ||
@@ -246,0 +247,0 @@ }, |
@@ -17,2 +17,3 @@ 简体中文 | [English](./README.md) | ||
<a href="https://www.npmjs.com/package/@axios-use/react" target="__blank"><img src="https://img.shields.io/npm/v/@axios-use/react.svg" alt="NPM version"></a> | ||
<a href="https://www.npmjs.com/package/@react-cmpt/react-request-hook" target="__blank"><img src="https://img.shields.io/badge/old%20version-v5.1.0-inactive.svg" alt="NPM old version"></a> | ||
<a href="https://github.com/axios-use/react/actions?query=workflow%3ACI" target="__blank"><img src="https://github.com/axios-use/react/workflows/CI/badge.svg" alt="ci"></a> | ||
@@ -109,3 +110,3 @@ <a href="https://github.com/axios-use/react/blob/main/LICENSE" target="__blank"><img src="https://img.shields.io/github/license/axios-use/react" alt="license"></a> | ||
// Promise function | ||
ready: () => Promise<[Payload<TRequest>, AxiosRestResponse]>; | ||
ready: () => Promise<[Payload<TRequest>, AxiosResponse]>; | ||
// Axios Canceler. clear current request. | ||
@@ -143,3 +144,3 @@ cancel: Canceler; | ||
{ | ||
onCompleted: (data, other) => console.info(data, other), | ||
onCompleted: (data, response) => console.info(data, response), | ||
onError: (err) => console.info(err), | ||
@@ -160,3 +161,3 @@ }, | ||
| options.filter | function | 请求筛选器,决定是否发起请求 | | ||
| options.defaultState | object | State 的初始化值. `{data, other, error, isLoading}` | | ||
| options.defaultState | object | State 的初始化值. `{data, response, error, isLoading}` | | ||
| options.onCompleted | function | 请求成功的回调函数 | | ||
@@ -187,4 +188,4 @@ | options.onError | function | 请求失败的回调函数 | | ||
data?: Payload<TRequest>; | ||
// other axios response. Omit<AxiosResponse, "data"> | ||
other?: AxiosRestResponse; | ||
// axios response | ||
response?: AxiosResponse; | ||
// normalized error | ||
@@ -243,3 +244,3 @@ error?: RequestError<Payload<TRequest>>; | ||
{ | ||
onCompleted: (data, other) => console.info(data, other), | ||
onCompleted: (data, response) => console.info(data, response), | ||
onError: (err) => console.info(err), | ||
@@ -246,0 +247,0 @@ }, |
82398
290
1164