Storing rendered components and state: how to persist across page reloads?
P粉052686710
P粉052686710 2023-09-11 10:47:00
0
1
420

I'm developing a dashboard application that users can customize to render components of their choice. Once they are configured, how do I save this state so that when the user revisits the application, it loads the same settings as when they left?

For example, I have the following components available:A, B, C, D, E. Users configure their dashboards to only renderA, C, D. I want the same components (A, C, D) and their respective states to be rendered when the user reloads or revisits the page. I don't want the user to have to reconfigure the application every time.

I considered storing the data in a text file, but I'm not sure how to convert that data back to the component. Any suggestions?

P粉052686710
P粉052686710

reply all (1)
P粉139351297

If you're talking about saving data in the browser, you have some options:

  • Local Storage
  • Indexed DB
  • Cookie

Client Storage

For React, you can also find things likeuseLocalStorage(similar touseState), which for example simplifies the above usage. Still, a pure browser API might be simple enough.

But, realistically, the solution may depend on how you define (identify) your "user". Is he the one who opened the browser? Or a logged in person in your app?

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!