DEV Community

Discussion on: Welcome Thread - v62

Collapse
tobilastik profile image
Raji Oluwatobiloba

Hello everyone, my name is Raji Oluwatobiloba, I am a software developer. I love to write and I am planning on using this platform to teach/communicate to people from my own little experience!

Collapse
faizanmustafa profile image
FaizanMustafa

Welcome Raji.. That's the great goal to teach people.. best of luck here

Collapse
sevenzark profile image
Dave M

Hi Raji! Same here, I think teaching is a fundamental way to solidify our own learning.

Collapse
travislramos profile image
Travis Ramos

Hello, nice to meet you! Awesome to see your already helping others out!

Collapse
loretoruiz profile image
Robinson Loreto

Hello how are you ? My name is Robinson and I write to you from Venezuela. I just started to learn Reactjs ... and I would like if you could guide me on the beginning of the session. I already have the Login interface and I redirect to the dashboard (in this case) ... but I don't know how to handle the user session? also the expiration time of that session? I've seen examples with LocalStorage but I don't know if that's a good practice ... I'd like to know if you can help me with an example? I did my backend with NodeJs Express connected to a Sql Server database ... Greetings...my email : loretoruiz@hotmail.com

Collapse
nekia profile image
Atsushin

Hi nice to meet you. You might be able to get some experience in the following project github.com/hyperledger/blockchain-... where I've joined as a OSS contributor. The project is using these tech stacks and always welcoming a new contributor. Cheers!

Collapse
tobilastik profile image
Raji Oluwatobiloba

Hi Robinson, happy to help. Can we chat on hangouts or whatsapp?

Thread Thread
loretoruiz profile image
Robinson Loreto

Hello, thanks for answering ... I do not speak English ... I speak Spanish ... but can you help me with the google translator ... can you show me an example of what I ask in the forum?

Thread Thread
tobilastik profile image
Raji Oluwatobiloba • Edited

Okay, if i were in your shoes, i'd use localstorage or cookies.
but I prefer localstorage.
normally you will be getting a token from the backend when you are logging users right? so just do it this way:

this will be at the point of logging in users
axios.post ('url', {
user,
})
.then (response => {
localStorage.setItem ('token', 'randomstringtokentopersistdata');

then on your dashboard page, just go like this.

const token = localStorage.getItem ('token');

you can store this token in a state and use it all over your app as it can be accessed anywhere.

Thread Thread
loretoruiz profile image
Robinson Loreto

I understand friend ... and how do you manage the session expiration time?

Thread Thread
tobilastik profile image
Raji Oluwatobiloba

You can use JavaScript session storage

sessionStorage.setItem('token', 'randomstring')

const data = sessionStorage.getItem('token');

// to remove user data from sessionStorage

sessionStorage.removeItem('token');

Thread Thread
loretoruiz profile image
Robinson Loreto

I understand friend ... I have a doubt ... how are global variables handled in Reactjs ?? that is ... if I want to save and be able to use the variable == >> const name = '' in ALL my application; that variable will take a value when the user enters the system ... and from another component I want to use it ... that is, I want to get the value of that variable name ... can you help me?

Thread Thread
tobilastik profile image
Raji Oluwatobiloba

You can store that variable in state and pass it as props to whatever component you need it(you'll need to read more on passing props) React official documentation is the best place to start.

Moreover, you'll reach a stage where passing this supposed variable from one component to another will be a pain in the ass, then you should use a state management, the popular one is redux. You'll need to go learn redux too. But for now, since you're just starting to learn react, try learning how to pass state as a props from one component to another.

Let me know if you need more clarification.

Collapse
soumil0702 profile image
soumil0702

Hello Raji, nice to meet you :)