React
Users

Current User

6min

Get current User for React

Introduction

After implementing user registration and login to your, you need to retrieve the currently logged user data to perform different actions and requests. This data can be promptly retrieved by using Parse.User.current inside your app components.

Prerequisites

To complete this tutorial, you will need:

Goal

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

1 - Retrieving Current User

The method Parse.User.current can be used anywhere on your code, after properly configuring your app to use Parse. 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 component

In our previous guides, the Parse.User.current method was already used for testing showing the current username on the User Login guide. Here is the UserLogin component code, take a closer look at the getCurrentUser function:

UserLogin.js
HelloUser.tsx


In this component, the Parse.User.current method retrieves the username and updates the state variable that is rendered inside the component JSX. Add these classes to your App.css file to fully render the layout styles:

App.css


Conclusion

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