React Native
...
Parse SDK (REST)
Users

Current User

7min

Get current User for React Native

Introduction

After implementing user registration and login to your, you need to retrieve the currently logged user data to perform different actions and requests. Since React Native uses AsyncStorage as the local storage, this data can be retrieved using Parse.currentAsync inside your app’s component.



Prerequisites

To complete this tutorial, you will need:

Goal

Get the current user data fetching using Parse for a React Native App.

1 - Retrieving Current User

The method Parse.currentAsync can be used anywhere on your code, after properly configuring your app to use Parse and AsyncStorage. Its response will be your current user’s object (Parse.User) or null if there is no logged-in user currently.

JavaScript
TypeScript


This method is essential in situations where you don’t have access to your application state or your user data, making it possible to perform relevant Parse requests in any component of your app.

2 - Using Current User in a React Native component

In our previous guides, Parse.currentAsync was already used for testing and inside the HelloUser component. Here is the complete component again:

HelloUser.js
HelloUser.tsx


In this case, the Parse.currentAsync method retrieves the username and updates the state variable that is rendered inside the component JSX.

Conclusion

At the end of this guide, you learned how to retrieve the current Parse user data from local storage on React Native. In the next guide, we will show you how to allow your user to reset his password.

Updated 21 Mar 2024
Did this page help you?