Suggest an editImprove this articleRefine the answer for “Where is component state stored?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**Component state** is actually not stored in the component's own function but inside React itself - in the internal structure (Fiber node) associated with that component. **Key point:** `useState` does not create a variable in your function, it registers it inside React Fiber, which is why the value "remembers" itself between calls of the component function.Shown above the full answer for quick recall.Answer (EN)Image### 1. At the code level When you write, for example: ```javascript function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; } ``` It seems as if `count` is stored simply in a variable inside the function. But this is **not the case**, because the function is called **again on every render**, which means all local variables inside it are reset. --- ### 2. Where `state` is actually stored In fact, **the state is stored inside React itself**, not in the component directly. During render, React creates an **internal structure (Fiber node)** for each component, where it keeps all the internal-service information: - the current state (`state`) - hooks (`useState`, `useEffect`, `useRef`, etc.) - references to child components - previous props and state - flags for updates, and so on That is, `useState` does not create a variable in your function, it **registers it inside React Fiber**. --- ### 3. What happens on `setState` / `setCount` When you call `setCount(newValue)`: 1. React **saves the new state value** in its internal structure (Fiber). 2. Marks the component as **"needing an update"**. 3. Re-renders the component (will call the `Counter()` function again). 4. On the new render, React **retrieves the saved state** and substitutes it into `[count, setCount]`. > So the value of `count` "remembers" its past, > even though the `Counter` function is called again and again. --- ### 4. Where exactly it is stored (simplified) If you picture it as a structure: ```javascript FiberNode = { type: Counter, stateHooks: [ { state: 0, queue: [updateFn1, updateFn2, ...] } ], props: {}, memoizedState: ..., ... } ``` Then the state is stored in `stateHooks` or `memoizedState` of the Fiber object, not in your function directly. --- ### 5. Summary: | Question | Answer | |---|---| | Where is the state stored? | Inside React (in the Fiber structure associated with the component). | | Why not in the function itself? | Because a component is just a function that gets called every render. | | How does React "remember" past state? | It stores it between function calls, in its internal component tree. |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.