I have been struggling from hours to solve this simple but tricky problem.
Am using react with redux. After user login into my application, i'll be having user object with fields like name profile_pic etc, am setting this to redux store and using those values where ever i want. It's working perfectly fine. But once page refresh/reload all redux state will rolled back to initial state.
To solve this am setting user object and authenticated flag in localStorage. I need to use this in home page component and all inner components.
But, getting from localStorage in all component lifecycle events will leads to code repetition.
I know, i can solve this by using libraries like redux-persist etc. But i don't want to use any libraries for this simple problem. Please sugest me a better way to do this. Thanks.
BTW - I tried following links, not worked/relevant for my case.
1. https://egghead.io/lessons/javascript-redux-persisting-the-state-to-the-local-storage
2.On React Router, how to stay logged in state even refresh the page?