Great question and something that beginners struggle with more often, so no worries if it doesn’t make sense straightaway. In React, a component is nothing more but a regular function that returns JSX. A re-render is the function being called again, because something changes, for example when a prop has changed its value. Every expression in the component is re-run on each render. So a statement like ‘let count = 0’ will re-run when the component re-renders, meaning that if something triggers a re-render, the count variable will always be re-initiated to 0. This is not desirable in a lot of cases, which is why React exposes the useState API. useState ensures that whatever the value of a state variable is, that that value will be the same when the component re-renders. In addition to that, if you use the setter function of useState, not only do you change the value, you also trigger a re-render, because there might be other parts of the component relying on the state variable. Does this help? Answer from mauricekleine on reddit.com
🌐
React
react.dev › reference › react › useState
useState – React
It should be pure, should take no arguments, and should return a value of any type. React will call your initializer function when initializing the component, and store its return value as the initial state. See an example below. useState returns an array with exactly two values:
🌐
W3Schools
w3schools.com › react › react_usestate.asp
React useState Hook
The React useState Hook allows us to track state in a function component.
Discussions

What problem does useState in React solve?
Great question and something that beginners struggle with more often, so no worries if it doesn’t make sense straightaway. In React, a component is nothing more but a regular function that returns JSX. A re-render is the function being called again, because something changes, for example when a prop has changed its value. Every expression in the component is re-run on each render. So a statement like ‘let count = 0’ will re-run when the component re-renders, meaning that if something triggers a re-render, the count variable will always be re-initiated to 0. This is not desirable in a lot of cases, which is why React exposes the useState API. useState ensures that whatever the value of a state variable is, that that value will be the same when the component re-renders. In addition to that, if you use the setter function of useState, not only do you change the value, you also trigger a re-render, because there might be other parts of the component relying on the state variable. Does this help? More on reddit.com
🌐 r/webdev
57
154
November 19, 2022
Can you explain react hooks and state to an idiot?
From the question you're asking, it's clear you're in a little over your head here. A lot has happened with react in the last couple years, including the introduction of hooks. They're great, we all love to use them in our functional components, however I'd take a moment to read the react documentation on how state works in both functional and class components just to get a basic understanding of how stateful components work. Understanding how state works in class components, which used to be the only kind of components, (before the introduction of hooks,) will make much more sense if you're new to react. It's really easy to see and understand the benefit of hooks/functional components once you understand the core concepts of state mgmt etc. Writing a class component or two will give you a clear idea of what hooks are doing "under the hood" and why you need a special function to update state etc. There's actually a modern, high level JavaScript feature called array destructuring behind the simple: const [state, setState] = useState(initialState) this basically equates to: const state = initialState const setState = helper function from react In short RTFM but ultimately I'd suggest writing one or two class components without hooks to get a sense of what state does for a component and how components work in the react virtual document object model(DOM). EDITs: way too many you probably won't read/need. More on reddit.com
🌐 r/reactjs
5
3
February 23, 2021
Why do we use "const" for useState instead of "let"?
The "remembering" happens outside of your function. When you call setState(), React maintain's it's own internal store where they keep track of values, and updates it there. It then it re-renders by calling App(), running your entire function again So when you are doing useState(), you are basically just asking react "Give me the current value of the [first] state variable used in the App component" and "Give me a function that lets me change it". So the value "count" here isn't the actual count that you can modify, but just the current value of what is in React's store when App() was ran. A tiny way to visualize it is as this: const getCount = () => 1; function App() { const count = getCount(); } More on reddit.com
🌐 r/reactjs
79
121
October 18, 2022
What is useState() and How to use ?
Hey Guys! Are you learning React at the moment ? This video is perfect for you! You will see how useState hook works inside a react functional… More on reddit.com
🌐 r/react
2
0
June 11, 2022
🌐
React
legacy.reactjs.org › docs › hooks-state.html
Using the State Hook – React
This is a way to “preserve” some values between the function calls — useState is a new way to use the exact same capabilities that this.state provides in a class. Normally, variables “disappear” when the function exits but state variables ...
🌐
Reacterry
reacterry.com › portal › deep-dive › use-state
useState | React Interview Prep Platform | reacterry
The useState hook is a way to add state to functional components in React. Prior to the introduction of hooks in React 16.8, state could only be used in class-based components. This often resulted in the need for complex prop drilling and wrapper ...
🌐
Dead Simple Chat
deadsimplechat.com › blog › react-usestate-the-complete-guide
React useState: The Complete guide
November 30, 2023 - Dead Simple Chat allows you to easily add Chat to any React Application using powerful Javascript Chat SDK. Adding state to a component. useState lets you add state to your functional components
🌐
React
react.dev › learn › you-might-not-need-an-effect
You Might Not Need an Effect – React
import { useState, useEffect } from 'react'; import { initialTodos, createTodo } from './todos.js'; export default function TodoList() { const [todos, setTodos] = useState(initialTodos); const [showActive, setShowActive] = useState(false); const [activeTodos, setActiveTodos] = useState([]); const [visibleTodos, setVisibleTodos] = useState([]); const [footer, setFooter] = useState(null); useEffect(() => { setActiveTodos(todos.filter(todo => !todo.completed)); }, [todos]); useEffect(() => { setVisibleTodos(showActive ?
Find elsewhere
🌐
Reddit
reddit.com › r/webdev › what problem does usestate in react solve?
r/webdev on Reddit: What problem does useState in React solve?
November 19, 2022 -

Im not good in javascript and we started doing React in school.

Ive seen countless videoes on useState and read about it, but i dont get what problem its trying to solve. They all just say how to use it, not why to use it. It just seems like a variable with extra steps.

Like if i wanted to make a counter, i could:

const [count, setCount] = useState(0)

Now i have a variable, with an initial value, and which i can only update with a function (for some reason, why is that smart?).

Why wouldnt i just write:

Let count = 0

Shouldnt that suffice? I can add and subtract to that too, and i dont need a specific function to do so. When i refresh the page, both values resets regardless.

Top answer
1 of 21
479
Great question and something that beginners struggle with more often, so no worries if it doesn’t make sense straightaway. In React, a component is nothing more but a regular function that returns JSX. A re-render is the function being called again, because something changes, for example when a prop has changed its value. Every expression in the component is re-run on each render. So a statement like ‘let count = 0’ will re-run when the component re-renders, meaning that if something triggers a re-render, the count variable will always be re-initiated to 0. This is not desirable in a lot of cases, which is why React exposes the useState API. useState ensures that whatever the value of a state variable is, that that value will be the same when the component re-renders. In addition to that, if you use the setter function of useState, not only do you change the value, you also trigger a re-render, because there might be other parts of the component relying on the state variable. Does this help?
2 of 21
34
Here's a demonstration of the difference: https://playcode.io/1015207 There are 2 things that useState is used for in this context: Maintaining the state across re-renders Triggering a re-render You can see both of those in action in the example above. Function components are just functions, so if something triggers a re-render of your component and you've used a regular variable that's initialised in the function itself (e.g. by using let count = 0) then it will always be reset its initial value on re-render. The useState hook stores this state elsewhere, and so is able to ensure your state is retained correctly across re-renders. When the component is unmounted, the state is released. The action of updating a component's state also triggers a re-render in itself though. In function components, if you just update a variable somewhere or modify the DOM manually, etc. then React isn't aware of it, so won't update what's rendered. Again, you can see this in the example above, attempting to update the count variable doesn't trigger a re-render. You can also see in the example that if you click to increment count, and then click to increment the hook-based count that only the hook based count increases, showing the value for count must have been reset when the re-render was triggered.
🌐
Contentful
contentful.com › blog › react-usestate-hook
React useState hook: Complete guide and tutorial | Contentful
May 13, 2025 - The React useState hook adds a state variable to a function component. Setting a state variable gives your component the ability to remember things across page re-renders, so that data can be stored and the component can be updated when the ...
🌐
npm
npmjs.com › package › use-react-state
use-react-state - npm
August 5, 2022 - import useState from 'use-react-state' const [state, setState, stateRef] = useState({ foo: 'foo' }) // merge state object setState({ bar: 'bar' }) // {foo: 'foo', bar: 'bar'} // replace state setState('foo') // 'foo' // replace state setState(['foo']) // ['foo'] // push state array setState(['bar']) // ['foo', 'bar'] // custom state setter setState((existingDraftState) => { return ['baz'] }) // ['baz']
      » npm install use-react-state
    
Published   Aug 05, 2022
Version   0.1.0-alpha.0
Author   myckhel
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › reactjs-usestate-hook
React useState Hook - GeeksforGeeks
The useState() hook allows you to add state to functional components in React.
Published   January 10, 2026
🌐
DEV Community
dev.to › sarioglu › how-to-store-a-function-using-react-usestate-4ffh
How to store a function using React.useState - DEV Community
September 9, 2020 - It is because update function of useState accepts either a value or a function to return a value: type SetStateAction<S> = S | ((prevState: S) => S); That's why when I passed a function to setMyFunc, React tried to get the return value of callback function by passing prevState to it as an argument.
🌐
freeCodeCamp
freecodecamp.org › news › usestate-hook-3-different-examples
How to Use the useState() Hook in React – Explained with Code Examples
May 8, 2023 - By Mwendwa Bundi Emma One of the most well-known React hooks is the useState() hook. It lets you add a state variable to your component. The useState() hook can conveniently hold strings, arrays, numbers, objects and much more.
🌐
upGrad
upgrad.com › home › tutorials › software & tech › react usestate hook
React useState Hook: Syntax, Examples & Best Practices Explained
January 30, 2025 - In React, the useState hook serves as a powerful tool that enables developers to integrate state management seamlessly within functional components.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › what-is-usestate-in-react
What is useState() in React ? - GeeksforGeeks
January 9, 2025 - The useState() is a Hook that allows you to have state variables in functional components . so basically useState is the ability to encapsulate local state in a functional component.
🌐
React
react.dev › learn › reacting-to-input-with-state
Reacting to Input with State – React
import { useState } from 'react'; export default function Form() { const [answer, setAnswer] = useState(''); const [error, setError] = useState(null); const [status, setStatus] = useState('typing'); if (status === 'success') { return <h1>That's right!</h1> } async function handleSubmit(e) { e.preventDefault(); setStatus('submitting'); try { await submitForm(answer); setStatus('success'); } catch (err) { setStatus('typing'); setError(err); } } function handleTextareaChange(e) { setAnswer(e.target.value); } return ( <> <h2>City quiz</h2> <p> In which city is there a billboard that turns air into drinkable water?
🌐
Medium
medium.com › @jbyj › okay-so-react-usestate-sucks-ef756cfce516
Okay, so React.useState Sucks
October 22, 2022 - React solves this by having a shared mutable global value that it assigns the relevant context data before calling the appropriate function to render the component (JS is single-threaded, so all synchronous in-order calls will reference the ‘right’ value during this process). The hook functions, like useState(), etc.
🌐
LinkedIn
linkedin.com › pulse › reacts-usestate-hook-manikandan-b
React's useState Hook
August 22, 2023 - In React, the useState hook is a function that allows you to add state management to functional components. It's one of the most essential hooks provided by React and enable to manage and update the state of your components without using class ...
🌐
Hygraph
hygraph.com › blog › usestate-react
useState() Hook in React - A Complete Guide | Hygraph
January 21, 2026 - In this guide, we have learned what state is and why it is important, we learned about the useState() hook from React which helps us to manage a component’s memory. We also learned about the lifecycle of a state variable and how the new state value is enforced after a component’s re-render.