fix: use force param only request hook

This commit is contained in:
Dmitriy Pleshevskiy 2021-06-18 01:01:30 +03:00
parent 3c1582ef9f
commit acddd23634
4 changed files with 8 additions and 4 deletions

View file

@ -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);
} }

View file

@ -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]

View file

@ -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);

View file

@ -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;