fix: use force param only request hook
This commit is contained in:
parent
3c1582ef9f
commit
acddd23634
4 changed files with 8 additions and 4 deletions
|
@ -99,7 +99,7 @@ export function useLazyRequest<E extends AnyEndpoint>(
|
||||||
&& isSameRequest
|
&& isSameRequest
|
||||||
&& state?.prevVariables && isEqual(state.prevVariables, variables)
|
&& state?.prevVariables && isEqual(state.prevVariables, variables)
|
||||||
&& state?.prevHeaders && isEqual(state.prevHeaders, headers)
|
&& state?.prevHeaders && isEqual(state.prevHeaders, headers)
|
||||||
&& !handlerConfig?.force
|
&& handlerConfig?.force === false
|
||||||
) {
|
) {
|
||||||
return Promise.resolve(state.data);
|
return Promise.resolve(state.data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@ export function useRequest<E extends AnyEndpoint>(
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
() => {
|
() => {
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
handler();
|
handler({
|
||||||
|
force: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[skip, handler]
|
[skip, handler]
|
||||||
|
|
|
@ -42,7 +42,7 @@ export function useLazyRequest(endpoint, config) {
|
||||||
&& isSameRequest
|
&& isSameRequest
|
||||||
&& (state === null || state === void 0 ? void 0 : state.prevVariables) && isEqual(state.prevVariables, variables)
|
&& (state === null || state === void 0 ? void 0 : state.prevVariables) && isEqual(state.prevVariables, variables)
|
||||||
&& (state === null || state === void 0 ? void 0 : state.prevHeaders) && isEqual(state.prevHeaders, headers)
|
&& (state === null || state === void 0 ? void 0 : state.prevHeaders) && isEqual(state.prevHeaders, headers)
|
||||||
&& !(handlerConfig === null || handlerConfig === void 0 ? void 0 : handlerConfig.force)) {
|
&& (handlerConfig === null || handlerConfig === void 0 ? void 0 : handlerConfig.force) === false) {
|
||||||
return Promise.resolve(state.data);
|
return Promise.resolve(state.data);
|
||||||
}
|
}
|
||||||
const onCompletes = [config === null || config === void 0 ? void 0 : config.onComplete, handlerConfig === null || handlerConfig === void 0 ? void 0 : handlerConfig.onComplete].filter(isFunction);
|
const onCompletes = [config === null || config === void 0 ? void 0 : config.onComplete, handlerConfig === null || handlerConfig === void 0 ? void 0 : handlerConfig.onComplete].filter(isFunction);
|
||||||
|
|
|
@ -8,7 +8,9 @@ export function useRequest(endpoint, config) {
|
||||||
const skip = React.useMemo(() => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.skip) !== null && _a !== void 0 ? _a : false; }, [config]);
|
const skip = React.useMemo(() => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.skip) !== null && _a !== void 0 ? _a : false; }, [config]);
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!skip) {
|
if (!skip) {
|
||||||
handler();
|
handler({
|
||||||
|
force: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [skip, handler]);
|
}, [skip, handler]);
|
||||||
return state;
|
return state;
|
||||||
|
|
Reference in a new issue