Can you share the component where you use the BuildProvider
? It's probably in your App.js
or a similar root component.
Ideally, it should be structured like this:
<BuildProvider>
<BrowserRouter>
<App />
</BrowserRouter>
</BuildProvider>
If your BuildProvider
is placed inside the BrowserRouter
or even inside individual route components, it might be getting unmounted and remounted during navigation. That would cause your context to reset and potentially overwrite the localStorage
with empty or default values, which are then reloaded as the new state.
Also, considering you're managing a lot of independent state values inside the provider, it might be worth looking into a more scalable state management solution like Zustand.