• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Generate Same Random Color with Page refresh in React

Resolved: Generate Same Random Color with Page refresh in React

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

In my application, I assign the same random color for the background color of the same uniqueID and I also want this color to be the same random color if the page reloads.
My approach and current behavior is similar to the solution in this prior post: Generate Random Same Colors in React however, the colors change if the page is reloaded.
Question: Is there a way to map the uniqueID to a random color, and have it persist different instances of my app using REACT?
See below my current code:

Answer:

You could use one of the various storage options to store this and then restore on each page load:
  • Cookies
  • Session
  • LocalStorage

If you have better answer, please add a comment about this, thank you!

javascript react-hooks reactjs typescript web-deployment
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I implement a function depending on picked up items?

01/04/2023

Resolved: Azuer Service Bus SDK not receiving the specified messages

01/04/2023

Resolved: how to change date format from 201904 to Apr-19 in excel

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.