Open codewithmohsen opened 1 year ago
now
https://stackoverflow.com/questions/71451505/use-react-context-with-local-storage
now it save and load from local storage and when i open new tabs it still saved! but in realtime other page's stare provider not change immidiately when localstorage changd.
Solution: This is expected, the context API is only meant to help you not have to pass properties down each element in a component tree. It does nothing for persistent state management. You'll need to add some code that both stores the state into something like localStorage and also loads it from localStorage on page load. See some code examples here: https://medium.com/@akrush95/global-cached-state-in-react-using-hooks-context-and-local-storage-166eacf8ab46
src: https://stackoverflow.com/questions/61580639/contextapi-loses-state-on-page-reload-and-when-opened-in-new-tab