Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React/Browser - Does any data get stored on a user's device with a useState hook, post a page refresh?

Given a use-case where there is a need for users to input data into a React application for the purposes of on-the-fly calculations. However, from a security perspective, the user-inputted data should not be persisted on the user's device, or within the React application (assume we are not explicitly saving that data anywhere from a React/backend logic perspective).

What happens to that data contained within useState hooks after the page is refreshed? Does React or the Browser store/cache any of that information at all, or is it deleted entirely?

like image 481
Interested Developer Avatar asked Oct 19 '25 05:10

Interested Developer


1 Answers

React state exists entirely in memory. I can only exist in longer term storage, like localStorage, if it's actively persisted there.

If you reload the browser window, it effectively remounts the React app. Anything that was running previously is tossed out and started anew. The app loads and any React components will have their initial state values.

What happens to that data contained within useState hooks after the page is refreshed? Does React or the Browser store/cache any of that information at all, or is it deleted entirely?

It is wiped on page reload, for the reason explained above.

like image 188
Drew Reese Avatar answered Oct 21 '25 20:10

Drew Reese



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!