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.


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


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".


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.




Install App

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