3

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?

Drew Reese
  • 165,259
  • 14
  • 153
  • 181

2 Answers2

2

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.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
1

It just gets restored to their initial state. And nothing else happens

const [post,setPost] = useState(false)

When the page refreshes it goes back to false

Frosty
  • 299
  • 5
  • 31