Reputation: 240
I am working on a small "google drive" web app. I store users and their objects. Some features are premium if you buy a subscription. Recently, I started using redux because I tired of "waterfalling" things like uid
from the top, to the bottom of the component tree through props.
My beginner-common-sense says "I should fetch subscription-status once, store it locally, and never make another subscription-status fetch again". BUT I have since run into situations where, say, the user upgrades their subscription, or it expires, and the source of truth has changed, but the local state has not.
Basically, I have a specific case where I could fetch user-state from the API EVERYTIME I load a specific component (like the landing page) OR I can fetch it once, and just be really careful about keeping local state up-to-date.
My worst fear is having out-of-sync state, like a user not having access to features they just bought.
In general, when should I:
versus
Rules of Thumb, best practices, any advice is welcome!
Upvotes: 0
Views: 577
Reputation: 173
In my opinion, you should store the subscription status locally as well, and if an user upgrades, just make sure that if the upgrade payment (or other criterion) was successful, refresh the subscription status.
Why this would be feasible is because an user is not expected to upgrade or modify their subscription status frequently.
Upvotes: 1