0

I am wondering where React store value of useState. SO lets say that we have

function counter() {
 const [count, setCount] = useState(0)
 return (<div className="counter">{count}</div>)
}

this component will return something like this: { type: 'div', props: { className: 'counter', children: null, etc... } }

So now I am not sure where count reference/value is located. Is is stored together with this component or it is separated from it?

1 Answers1

0

it's stored in the browser's local memory, that's why whenever values are stored in a react store, whether it's stored by a useState, useReducer or any third-party state management library like Redux, is refreshed all values stored are lost except maybe it's initial state, or when it's stored in the localStorage of browser.

Read more about React state from this article... What Every React Developer Should Know About State

Frankelly
  • 38
  • 7