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

134
Visualizações
Retreive current user data without reload the page - React native

I'm trying to get current user in drawer of react navigation by using AsyncStorage so when I login the function doesn't invoked till I refresh the page two times even I call it in the useEffect fun, May someone help me to solve this issue please!

Drawer Component:

import {
    DrawerContentScrollView,
    DrawerItem
} from '@react-navigation/drawer';

    const [email, setEmail] = useState()
    const [items, setItems] = useState({})
    
     useLayoutEffect(() => {
    
    
   getCurrentUser()
   
}, [])

const getCurrentUser = async() => {

    try {

        AsyncStorage.getItem("userName", (err, result) => {
            setEmail(result)
       });

      await AuthService.getCurrentUser(email)
        .then(response => {

            setItems(response.data);
           // setLabel(items.firstName.charAt(0)+items.lastName.charAt(0))

        })
        .catch(e => {
            console.log(e);
        });

        
    } catch (error) {
        console.log(error);
    }
    
        
}
<Provider>
            <View>
                <DrawerContentScrollView>

                    <View>
                        <View>
                            <View>
                                <Avatar.Text
                                    label='{items.firstName}'
                                    size={52}
                                    color='white'
                                />


<View>
<Title> {items.firstName} {items.lastName}
  </Title>

      <Caption>{email}</Caption>
         </View>...

App.js:

<PaperProvider>
          <NavigationContainer>
          
              <Drawer.Navigator
              initialRouteName="LoginScreen"
              screenOptions={{
                headerShown: false,
                headerTransparent:true
              }}
              drawerContent={props => <DrawerContent {...props} />}>
          ....

Error:

Request failed with status code 404 at node_modules\axios\lib\core\createError.js:16:14 in createError at node_modules\axios\lib\core\settle.js:17:22 in settle at node_modules\axios\lib\adapters\xhr.js:66:12 in onloadend at node_modules\event-target-shim\dist\event-target-shim.js:818:20 i..

So here is the whole code, I'm trying to get data of current user and display it on the header of the drawer navigation.

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