Skip to content

Commit

Permalink
fix: immediately return new data from RTK
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed May 11, 2023
1 parent 28c5c7e commit 58a8022
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/utils/fetchUtils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {useMemo, useRef} from 'react';

import {BaseQueryFn, FetchArgs, FetchBaseQueryError, fetchBaseQuery} from '@reduxjs/toolkit/dist/query';
import {UseQuery} from '@reduxjs/toolkit/dist/query/react/buildHooks';

import {ParsedQuery} from 'query-string';

import {isEqual} from 'lodash';

import {searchParamsLists} from '@constants/searchParams';

import {SearchParamKey, SearchParamsKeys, SearchParamsType, ValidatedSearchParams} from '@models/searchParams';

import {isArraylikeQueryParam} from '@utils/strings';

import {getApiEndpoint} from '@services/apiEndpoint';
import {useEffect, useRef} from 'react';
import {isEqual} from 'lodash';

const prohibitedValues = ['undefined', 'null'];

Expand Down Expand Up @@ -156,7 +158,7 @@ export function memoizeQuery<T extends UseQuery<any>>(
const dataRef = useRef<U>(result.data);
const transformedRef = useRef<U>(result.data);

useEffect(() => {
useMemo(() => {
if (dataRef.current !== result.data) {
const next = result.data == null ? result.data : transformData(result.data);
if (!isEqual(next, transformedRef.current)) {
Expand Down

0 comments on commit 58a8022

Please sign in to comment.