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

How do I properly use React Query with Jotai and Supabase in React Native? "Query Data cannot be undefined..."

$
0
0

So I'm trying to implement React Query to the point where the result is set into my Jotai atoms. I'm running into this error when I try to use it:

WARN  Query data cannot be undefined.Please make sure to return a value other than undefined from your query function.Affected query key: ["user-profile", "THIS IS A USER ID"]WARN  [Error: undefined]

This is what I have going on:

userProfileAtom.ts

This is a logged-in user profile atom that I use across my app.

import { atom } from 'jotai';import { SupabaseUserProfile } from '@interfaces/interfaces';export const userProfileAtom = atom<SupabaseUserProfile | null>(null);

getProfileById.ts

This is the structure of the query to get a single profile back from the database.

export function getProfileById(client: SupabaseClient, profileId: string) {  return client    .from('profiles')    .select('*')    .eq('id', profileId)    .throwOnError()    .single();}

useProfileQuery.ts

This is the hook I created that I use in my components to make the request. Here I am trying to set my atom to the result.data of the request. This is also where the error occurs.

function useProfileQuery(profileId: string) {  const client = useSupabase();  const key = ['user-profile', profileId];  const [, setUserProfile] = useAtom(userProfileAtom);  return useQuery(key, async () => {    return getProfileById(client, profileId).then(result =>      setUserProfile(result.data),    );  });}export default useProfileQuery;

What am I doing wrong in handing in the result.data?

My component that uses it example:

  const { data, isLoading } = useProfileQuery(userID);

Viewing all articles
Browse latest Browse all 6290

Trending Articles



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