Skip to content

RefetchOnMountOrargChange keeps the isFetching always true #3580

Open
@Irfanwani

Description

@Irfanwani

When setting RefetchOnMountOrargChange prop to true in a query, it only works fine on the first render. If i refresh the app, then the query is stuck in the loading state. Nothing special in the code;

const {data, isFetching, error, refetch} = useMyQuery(user_id, {
  refetchOnMountOrArgChange: true,
});

EDIT

This is the whole component;

import {SectionList, VStack} from 'native-base';
import {FC, useMemo, useState} from 'react';
import {BackHandler} from 'react-native';
import {useSelector} from 'react-redux';
import {
  NoBoards,
  Sectionheader,
  workspaceRenderItem,
} from '../../components/screencomponents/listcomponents';
import {Loader} from '../../components/utils/utils';
import {useGetworkspacesQuery} from '../../store/apislices/boardapislice';
import {useIsReady} from '../../utils/customhooks';
import {errorHandler} from '../../utils/errorhandler';
import {WorkspaceProps, WorkspaceRenderItemProps} from './types';

const WorkSpaces: FC<WorkspaceProps> = ({navigation}) => {
  const user_id = useSelector<any, any>((s) => s?.user?._id);

  const {data, isFetching, error, refetch} = useGetworkspacesQuery(user_id, {
    refetchOnMountOrArgChange: true,
  });

  useEffect(() => {
    if (error) errorHandler(error);
  }, [error]);

  const allspaces = useMemo(
    () => [
      {
        title: 'My Workspaces',
        data: data?.allWorkspaces ?? [],
      },
      {
        title: 'Guest Workspaces',
        data: data?.allguestWorkspace ?? [],
      },
    ],
    [data],
  );

  const renderItem = ({item, index, section}: WorkspaceRenderItemProps) => {
    let ind = section?.title?.includes('Guest')
      ? allspaces?.[0]?.data?.length + index
      : index;
    const onPress = () => {
      navigation.navigate('boards', {index: ind});
    };

    return workspaceRenderItem({item, index: ind, onPress});
  };

  const notReady = useIsReady();

  if (notReady) return <Loader />;
  return (
      <SectionList
        refreshing={isFetching}
        onRefresh={refetch}
        sections={allspaces ?? []}
        renderItem={renderItem}
        ListEmptyComponent={
          !isFetching ? <NoBoards screenname="workspace" /> : null
        }
        renderSectionHeader={Sectionheader}
        stickySectionHeadersEnabled
        ListFooterComponent={<VStack p="5" />}
      />
  );
};

export default WorkSpaces;

Metadata

Metadata

Assignees

No one assigned

    Labels

    RTK-QueryReact-NativeIndicates an issue specific to the React Native environmentneeds reproductionReport is waiting on a reproduction

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions