I understand using a React Hook

In this article I will explain in a simple way how to use the "useState" react hook, for this example I will create a button component using chakra-ui to style the button, which will have the login function, which will show if the user is logged in or logged out.

code-snapshot-component.png

Here we will create the variable that will be responsible for managing the component state.

code-snapshot-usestate.png

Now that we've set our state, we can create our handleUserLoggedIn function which will set the state of the isUserLoggedIn variable to the opposite of what it currently is ie "true" or "false".

code-snapshot-handleuserloggedin.png

Using another react hook, useEffect, with it we will store it in the browser's localStorage as true or false depending on the state of isUserLoggedIn when clicked, that is, if the user is logged in or out of the platform.

code-snapshot-useeffect.png

Company

PostsCareersContato

Install App

©2022 Aleksander Palamar. All rights reserved | CNPJ 26.328.604/0001-55