Skip to content
Advertisement

Save a prop when moving away and coming back to page ReactJS

I have a username property that I have passed on from “log in” route to “product list” route using

JavaScript

I then have a <Link to={'/products/${product.id}'}>More info</Link> that sends me from “product list” to an “individual product”.

When I then come back to the “product list” <Link to={'/products'}>Back</Link>, the username is gone. Is there a way to keep the username, so when the user is logged in and moves back and forth between routes, it keeps being stored?

Here is the full code for my “product list” route where I want the username to be stored:

JavaScript

Advertisement

Answer

SOLVED: Solved it by passing on the username prop further to the “individual product” component. That way when I hit back to the “product list”, the username stays.

Or even better storing Username in the sessionStorage.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement