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

130
Views
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
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!