Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6312

useQuery used in custom hook returns a response with type useQueryResults

$
0
0

I have the following custom hook called useFocusRefetchQuery

type Props = Parameters<typeof useQuery>;const useFocusRefetchQuery = (...params: Props) => {    const useQueryResults = useQuery(params);    useFocusEffect(        React.useCallback(() => {            useQueryResults.refetch();        }, [useQueryResults])    );    return useQueryResults;};

Which I then call in useGetArticle like this:

export const useGetArticle = (articleId: string) => {    return useFocusRefetchQuery(['getArticle', { articleId }], () => getArticle(articleId), { staleTime: 0 });};

And useGetArticle is called like this

const { data: article, isLoading } = useGetArticle('home');

My problem is that in this case, article has a type of unknown and I can't figure out why is this happening. My guess is that I have to somehow type what is being returned by useFocusRefetchQuery. Before I implemented the custom hook, Typescript automatically inferred the return type of useQuery


Viewing all articles
Browse latest Browse all 6312

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>