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

useQuery used in custom hook returns a response with type useQueryResults

$
0
0

I have the following custom hook called useGetQuery

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

Which I then call in useGetScreen like this:

export const useGetScreen = (screenId: string) => {    return useGetQuery(['getScreen', { screenId }], () => getScreen(screenId), { staleTime: 0 });};

And useGetScreen is called like this

const { data: screen } = useGetScreen('vegetables');

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 6290

Trending Articles