1

I am not sure how to handle this behavior, this is the Feature I have:

public class HolderFeature : Feature<HolderState>
    {
        public override string GetName() => "HolderState";
        protected override HolderState GetInitialState() => new(holder: new ProductHolder(), persons: string.Empty);        
    }

And, everything works fine until a page is refreshed (pressing f5), the state is wiped out, I have this to handle the error:

 protected override void OnInitialized()
        {
            if (HolderState.Value.QuotedProduct.Quotes != null)
            {
                //do the logic
            }
            else
            {
              //show error screen
                PressedF5 = true;
            }
        }

What I expect is that even when the page is refreshed it shouldn't wipe out the state. how can I do that?

paburgos
  • 259
  • 2
  • 14
  • What is the question? What is the problem? It's expected for the state to be wiped out when you refresh -- is that your point? – Kirk Woll Dec 20 '21 at 18:52
  • @KirkWoll you are right! I edited the post hope this time it is understandable. – paburgos Dec 20 '21 at 20:06
  • 2
    To persist state upon a refresh, you need to store the state somewhere -- either a server-backed database, or browser local storage. That's a topic too big for an SO question, but [this tutorial](https://dev.to/mr_eking/advanced-blazor-state-management-using-fluxor-part-6-l04) seems to be what you're after. – Kirk Woll Dec 20 '21 at 21:26
  • I imagined something with local storage or indexdb would be the answer! Thank you if you post your previous post I will mark it as the answer. – paburgos Dec 20 '21 at 22:19
  • 1
    A related question with a library to persist Fluxor data to DB or localStorage on F5. See: https://stackoverflow.com/a/67421834/943435 – Yogi Dec 21 '21 at 07:17

1 Answers1

1

The state is stored in memory. When you refresh the page you are unloading it and starting from scratch, so all the memory is lost if it isn't persisted somewhere.

Peter Morris
  • 20,174
  • 9
  • 81
  • 146