Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
base de fuego | Devuelve Undefined al regresar, pero console.log funciona

Actualmente estoy tratando de actualizar mi pequeño rastreador de peso personal usando Firebase y React Native. Sin embargo, cada vez que registro DataSnapshot.val() , recibo la entrada 22 , que es perfecta. Pero cuando devuelvo el mismo valor, recibo Undefined .

Probé get() y onValue() con los mismos resultados. La ruta es correcta, ya que obtengo los datos correctos usando console.log.

https://firebase.google.com/docs/database/web/read-and-write?authuser=2

Intenté seguir la documentación anterior. Pero esta actualizado? snapshot es actualmente DataSnapshot ?

base de fuego:

 const readWeight = (database, userId) => { get(ref(database, `users/${userId}/weight`)).then((DataSnapshot) => { try { if (DataSnapshot.exists()) { console.log( `Weight found. Current weight is: ${DataSnapshot.val()} kg` ); return DataSnapshot.val(); } else { console.log("Weight wasn't found"); } } catch (error) { console.log(error); } }); };

Pantalla de inicio.js

 // Modules import { react, useState, useEffect } from "react"; import { Text, TouchableOpacity, View, TextInput, Image } from "react-native"; import { LogOutButton } from "../Components/LogOutButton"; import { auth, writeUserData, database, readWeight } from "../firebase"; // Stylesheet import { styles } from "../Stylesheet/Stylesheet"; export const HomeScreen = () => { const user = auth.currentUser; let currentUserWeight = readWeight(database, user.uid); console.log("Current Weight: ", currentUserWeight); return ( <View style={styles.profileMain}> <View style={styles.profileInfoContainer}> <View style={styles.HOME__profileWeightContainer}> <Text style={styles.HOME__profileWeightText}> Last Weight: {currentUserWeight} </Text> </View> </View> </View> </View> ); };
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!