0

After updating useState defined in useContext of react with a child component, is there a way to retain the value (holds the updated value) even if it transitions to another page and reloads?

UseState "initial value" called A defined in useContext, In child component A, change it to "I changed it".

In another child component B, I want to be able to refer to the updated "changed" in useState of useContext even if it is reloaded. Is it possible with useContext?

When I looked it up, I thought it would be good to do a process called Recoil persistence, but what about ...

Or should I save it in the local strage? I want to save some personal information, so it's not very appropriate ...

If anyone knows a good way, please let me know.

dksq
  • 3
  • 2
  • 2
    If your page is reloaded you will lose all the data in your state. Going to another page is a different thing, if you use react-router you can keep your state while changing the pages. If this not the case and you need to store your data in local storage or cookie. You can also build your component to fetch latest data from an API when the page is reloaded. – hurricane Apr 03 '21 at 11:13
  • opps did not read full question, maybe store it in a backend database and fetch it with an api? – Laurenz1606 Apr 03 '21 at 11:11

0 Answers0