0

I am new to react and redux. I have 3 screens in my react js application. On First Screen, user input the id and that id get stored in redux store. On submit of first screen button API is called which take id as a parameter and bring the data. I Store that data in redux store. On Second Screen, I show that data after fetching it from store. Problem arises when I reload the page, the data of redux store get initilized to initial state i.e. empty.

I want when I reload the page, request should again go to server and fetch the data.

NOTE - I dont have access to id on second screen after reload so I cant call API again inside useEffect Hook. Secondly I dont want to store data in any storage.

Kindly assist. Thank You

Akshat Saxena
  • 11
  • 1
  • 4
  • If you can't requery the API, and you can't persist it using some sort of browser storage, then I'm not sure you have any options left. Is there a reason why you don't want to use any storage? Could you put the `id` in a query param or something? – Brian Thompson Mar 31 '22 at 18:40

2 Answers2

1

If you want to persist state using redux. I recommend you go for redux persist. It's what I use.

Bakersen
  • 41
  • 4
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33367708) – Vojin Purić Dec 13 '22 at 15:13
0

Unfortunately, redux or any react state is not maintained throughout a browser refresh without some sort of persistence to either a DB, or browser storage like localStorage or indexedDB.

IF you do decide to persist the redux store to maintain state through browser refreshes... I hear redux-persist is great for it. https://www.npmjs.com/package/redux-persist. It will use local-storage or session storage depending on how it's configured.