I am using react-native 0.81.4 CLI along with the following Firebase packages:
"@react-native-firebase/app": "^23.5.0",
"@react-native-firebase/firestore": "^23.5.0",
"@react-native-firebase/messaging": "^23.5.0",
My code:
import {
useCallback
} from 'react';
import {
Alert
} from 'react-native';
import {
getFirestore,
collection,
doc,
setDoc,
serverTimestamp,
} from '@react-native-firebase/firestore';
import {
getApp
} from '@react-native-firebase/app';
import {
TUser
} from '@/typescript/types/user';
const useSaveUser = () => {
const onGetUserById = useCallback(async (userId: string, userPayload: Partial < TUser > ) => {
try {
console.log('Saving user to Firestore:', userId, userPayload);
const db = getFirestore(getApp()); // modular way
console.log('Modular way crossed');
const userDocRef = doc(collection(db, 'users'), userId);
console.log('Document reference has been created');
await setDoc(userDocRef, {
...userPayload,
createdAt: serverTimestamp(),
});
console.log(' User saved successfully for ID:', userId);
Alert.alert('User saved successfully');
} catch (error) {
console.error(' Firestore Save Error:', error);
Alert.alert("Unable to save user's information");
}
}, []);
return {
onGetUserById
};
};
export default useSaveUser;
Usage:
const {
onGetUserById
} = useSaveUser();
const [isLoading, setIsLoading] = useState(false);
const handleSubmit = async () => {
try {
setIsLoading(true);
const userPayload = {
id: 'id as string',
firstName: 'givenName as string',
lastName: 'familyName as string',
email: 'email as string',
photo: 'photo as string',
};
console.log('just before');
const response = await onGetUserById('1', userPayload);
console.log({
response
});
} catch (e) {
console.log('Sign-In error:', e);
} finally {
setIsLoading(false);
}
};
return ( <Pressable disabled = {
isLoading
}
onPress = {
handleSubmit
}>
<Text>Continue</Text>
</Pressable>
)
Logs:
The main issue I am facing is that when I trigger the Firebase function, my code gets stuck on the save method, and I don't get an error, success or even a timeout!

console.log({response});instead ofconsole.log(response);?