Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

89
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda