Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
Awaiting results from database before rendering page

I am building an app with react native, in which I need to pull data from a database (firebase) before rendering a page. I am having a hard time getting variables to update before the return is called. I also cannot change the default export to a class, since I am planning on using a feature (image picker) that requires hooks. I have included similar code to what I have below.

export default function ProfileScreen(){
  let displayName = ""
  let skillLevel = "Iron 2"
  let mainCharacter = "Astra"

    useEffect(() => {

      populateFieldsFromDB()

    }, [])


  const populateFieldsFromDB = async () => {
    let userUUID = await SecureStore.getItemAsync("userUUID")
    if(userUUID != null){
      const user = await firebase.firestore().collection("Users").doc(userUUID).get()
      if("displayName" in user.data()){
        displayName = user.data().displayName
      }
      if("rank" in user.data()){
        skillLevel = user.data().rank
        console.log(skillLevel)
      }
      if("main" in user.data()){
        mainCharacter = user.data().main
      }
    }
  }

return(
        <TextInput
          style={styles.textField}
          onChangeText={text => onDisplayNameChange(text)}
          defaultValue={displayName}
          placeholder='Enter your Riot Name and discriminator (i.e. John#1234)'
          keyboardAppearance="dark"
          placeholderTextColor="#003800"
        />
)

In this case, the default value of the text input is the empty string, not what gets updated after the populateFieldsFromDB() call. Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda