Skip to content

Commit

Permalink
perf(expo-bbq): wrapped the userData into a memo.
Browse files Browse the repository at this point in the history
  • Loading branch information
h0lybyte committed Nov 10, 2024
1 parent 4dbbf4f commit 300874b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/expo-bbq/src/components/auth/user/TamaOnboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@ export function TamaOnboard({
[supabaseUrl, supabaseAnonKey],
);

// [User] -> Memoize the user object.
const user = useMemo(async () => {
return (await supabase.auth.getUser())?.data.user;
}, [supabase]);


// Handler to submit the username
const handleUsernameSubmit = useCallback(async () => {
try {

const user = (await supabase.auth.getUser())?.data.user;

const userData = await user;
if (!userData) throw new Error('UserData not found');

const { error } = await supabase
.from('user_profiles')
.update({ username })
.eq('id', user?.id);
.eq('id', userData.id);

if (error) throw error;

Expand All @@ -46,19 +53,20 @@ export function TamaOnboard({
setError('Failed to set username. Please try again.');
console.error(err);
}
}, [username, supabase]);
}, [username, user, supabase]);

// Handler to submit the user card details
const handleUserCardSubmit = useCallback(async () => {
try {

const user = (await supabase.auth.getUser())?.data.user;

const userData = await user;
if (!userData) throw new Error('UserData not found');


const { error } = await supabase
.from('user_profiles')
.update({ bio, socials, style })
.eq('id', user?.id);
.eq('id', userData.id);

if (error) throw error;

Expand All @@ -67,7 +75,7 @@ export function TamaOnboard({
setError('Failed to save user card details. Please try again.');
console.error(err);
}
}, [bio, socials, style, supabase, router]);
}, [bio, socials, style, user, supabase, router]);

return (
<YStack
Expand Down

0 comments on commit 300874b

Please sign in to comment.