Skip to content

RTK Query refetch with React Native RefreshControl #1167

Answered by makirby
makirby asked this question in Q&A
Discussion options

You must be logged in to vote

Solution for now was to create a separate hook to handle manual refresh passing in the isFetching flag like @phryneas mentioned.

import { useEffect, useMemo, useState } from 'react';

interface Options {
	refresh: () => void;
	isFetching: boolean;
}

const useManualRefresh = ({ refresh, isFetching }: Options) => {
	const [refreshRequested, setRefreshRequested] = useState(false);

	const requestRefresh = () => {
		setRefreshRequested(true);

		refresh();
	};

	useEffect(() => {
		if (refreshRequested === true && isFetching === false) {
			setRefreshRequested(false);
		}
	}, [refreshRequested, isFetching]);

	const refreshing = useMemo(() => {
		return refreshRequested === true && isFetching 

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@makirby
Comment options

@phryneas
Comment options

@makirby
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by makirby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants