From React 16.8.0 You can use Hooks using useState to instantiate a State custom in your Functional Component. Like This...

import React, {useState} from 'react';

const AddButon = ({handleAddValue}) => {
  return <button onClick={handleAddValue}>Add</button>
}

const App = (props) =>{

  const [value, setValue] = useState(0);

  const handleAddValue = () => {
    const newValue = value+1;
    setValue(newValue);
  }

  return (
    <div>
      <div>The Value is: {value}</div>
      <AddButon handleAddValue={handleAddValue} />
    </div>);
}

If you want to read more about this new functionality, follow the following link.

https://reactjs.org/docs/hooks-intro.html

Answer from Rafael Maldonado on Stack Overflow
🌐
How-To Geek
howtogeek.com › home › how to use state in functional react components
How to Use State in Functional React Components
March 31, 2021 - Clicking the button will increment the value. With such a simple component, it would be ideal to rewrite this as a functional component. To do so, you'll need to use the useState() hook.
Discussions

React: How to use setState inside functional component?
In function-based components state can be stored using useState hook. The name of the state variable can be anything. Just like the class component here, we have two items returned by the useState hook. More on stackoverflow.com
🌐 stackoverflow.com
reactjs - Usage of State in functional component of React - Stack Overflow
In order to update state in functional component you need to update it with appropriate function. useState returns 2 values first is current state value and second one function to update that state More on stackoverflow.com
🌐 stackoverflow.com
May 18, 2021
reactjs - How to use state in this functional component? - Stack Overflow
I want to use this state in this code but I got this error: 'state' is not defined how can I use that? I know that I can use class component but it give me an error for using let settings too. an... More on stackoverflow.com
🌐 stackoverflow.com
Is it a good idea to use getters and setters to access component state? (ReactTypescript)
No, you dont need this. Its too verbose, too OOP, and react is more functional prog-like And no one use get / set in react projects :) PS: you dont need the constructor more too. just use: state = { myVar: '' } More on reddit.com
🌐 r/reactjs
4
4
January 14, 2019
🌐
DEV Community
dev.to › austinbrownopspark › react-using-state-in-functional-components-2bc4
React: Using State in Functional Components - DEV Community
August 24, 2020 - Traditionally in React JS, an app ... way that there is a main stateful class component which holds all of the state values and methods to set them with, and these values or methods would be passed to its functional children components as props...
🌐
Ordinarycoders
ordinarycoders.com › blog › article › react-functional-components-state-props
React Functional Components: State, Props, and Lifecycle Methods
The state of a component in React is a plain JavaScript object that controls the behavior of a component. The change in a state triggers component re-renders. Two main React hooks are used to declare and manipulate the state in a function component.
Top answer
1 of 4
9

There is only the (one) 'setState()' method - not a method per-property (as you've suggested/questioned).

It is a composite in terms of it's parameter, in that you can specify/set more than one item within the same/one call (to the 'setState()' method), so you can set all 20 of your items in one go.

E.g.

  this.setState({ "firstName" : firstNameVal, "lastName" : lastNameVal });

I was starting from where you said you started - from a 'class' based component.

If you are sticking with the switch to a 'function' based component, then it is slightly different, in summary:

import React, { useState } from 'react';

...

// The 'useState' hook (function) returns a getter (variable) & setter (function) for your state value - and takes the initial/default value for it/to set it to, e.g.
const [ firstName, setFirstName ] = useState('');

And you then use the getter var to read it & the setter function to set it:

  setFirstName('Dennis');

(I could be wrong but I believe 'hooks' were added in v16.8 of React.)

A more in-depth description:

https://www.simplilearn.com/tutorials/reactjs-tutorial/reactjs-state#:~:text=1%20A%20state%20can%20be%20modified%20based%20on,merge%20between%20the%20new%20and%20the%20previous%20state

2 of 4
8

Use useState hook in functional components.

const App = () => {
  const [state, setState] = React.useState({ first: "hello", second: "world" });
  
  return (
    <div>
      <input type="text" value={state.first} onChange={(ev) => setState({...state, first: ev.target.value})} />
      <input type="text" value={state.second} onChange={(ev) => setState({...state, second: ev.target.value})} />
    </div>
  )


}


ReactDOM.render(<App />, document.getElementById('app'))
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>

<div id="app"> </div>

🌐
React
legacy.reactjs.org › docs › hooks-state.html
Using the State Hook – React
We declare a state variable called count, and set it to 0. React will remember its current value between re-renders, and provide the most recent one to our function. If we want to update the current count, we can call setCount.
🌐
W3Schools
w3schools.com › react › react_usestate.asp
React useState Hook
At the top of your component, import the useState Hook. ... Notice that we are destructuring useState from react as it is a named export. To learn more about destructuring, check out the ES6 Destructuring section.
Find elsewhere
🌐
Medium
rajeshnaroth.medium.com › component-state-management-in-react-functional-components-with-hooks-e7c412c05e71
Component State Management in React Functional Components with hooks
June 25, 2020 - It is not possible to persist state in local variables as these are initialized every time the function is evaluated. Thus to maintain state inside the function, React provides several hooks: useState() hook allows you create and mange ...
🌐
Medium
medium.com › @spfohman_90079 › using-react-state-with-functional-components-f5e22ebca411
Using React State with Functional Components | by Sarah Pfohman | Medium
November 29, 2021 - To use state within the functional component, it needs to be called or imported at the top of the component. ... To initialize state, you create a destructured array, the initial value being the item to update, and the second value is the function ...
🌐
Robin Wieruch
robinwieruch.de › react-function-component
React Function Components - Robin Wieruch
December 23, 2024 - The function executes delayed without any further instructions from your side within the component. The component will also rerender asynchronously in case props or state have changed. Take the following code as example to see how we set state with a artificial delay by using setTimeout: ... import React, { useState } from 'react'; const App = () => { const [count, setCount] = useState(0); const handleIncrement = () => setTimeout( () => setCount(currentCount => currentCount + 1), 1000 ); const handleDecrement = () => setTimeout( () => setCount(currentCount => currentCount - 1), 1000 ); return ( <div> <h1>{count}</h1> <Button handleClick={handleIncrement}>Increment</Button> <Button handleClick={handleDecrement}>Decrement</Button> </div> ); }; const Button = ({ handleClick, children }) => ( <button type="button" onClick={handleClick}> {children} </button> ); export default App;
🌐
Carl Rippon
carlrippon.com › managing-state-in-functional-react-components-with-usestate
Managing State in Functional React Components with useState
December 4, 2018 - The useState function takes in the default value of the state and returns a two element array containing the state variable and a function to set the value of the variable.
🌐
UMA Technology
umatechnology.org › home › how to use state in functional react components
How to Use State in Functional React Components - UMA Technology
December 21, 2024 - This helps keep components self-contained and makes it easier to manage and update data within a component. ... In functional components, state is managed using the useState hook, which is a function provided by React that allows components to declare and update state variables.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-manage-state-with-hooks-on-react-components
How To Manage State with Hooks on React Components | DigitalOcean
July 14, 2020 - The useState Hook is valuable when setting a value without referencing the current state; the useReducer Hook is useful when you need to reference a previous value or when you have different actions the require complex data manipulations. To explore these different ways of setting state, you’ll create a product page component with a shopping cart that you’ll update by adding purchases from a list of options. By the end of this tutorial, you’ll be comfortable managing state in a functional component using Hooks, and you’ll have a foundation for more advanced Hooks such as useEffect, useMemo, and useContext.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › what-is-state-in-react
State in React Functional Component - GeeksforGeeks
July 23, 2025 - Reactivity: When the state changes, React re-renders the component to reflect the updated state in the UI. State is Immutable: You should never directly modify the state. Instead, you use functions to update it.
🌐
React
react.dev › reference › react › useState
useState – React
Call useState at the top level of your component to declare a state variable. ... The convention is to name state variables like [something, setSomething] using array destructuring.
🌐
GeeksforGeeks
geeksforgeeks.org › what-is-usestate-in-react
What is useState() in React ? - GeeksforGeeks
January 9, 2025 - The useState hook is a function that allows you to add state to a functional component. It is an alternative to the useReducer hook that is preferred when we require the basic update. useState Hooks are used to add the state variables in the ...
🌐
DEV Community
dev.to › a26230203 › use-state-in-functional-component-of-react-5c0m
Use State in functional component of React - DEV Community
May 13, 2021 - Then here we have dog as state variable and setDog as the function to update the dog. The useState Hook only allow one state variable being declare at once, in other words if you have multiple state, you should create multiple variables. Like we using setState in Class components, we are going to use setDog in Functional components to updated the value of dog
🌐
LogRocket
blog.logrocket.com › home › usestate in react: a complete guide
useState in React: A complete guide - LogRocket Blog
October 22, 2024 - The Hook takes an initial state value as an argument and returns an updated state value whenever the setter function is called. It can be used like this: ... Here, the initialValue is the value you want to start with and state is the current ...
🌐
Stack Overflow
stackoverflow.com › questions › 66679716 › how-to-use-state-in-this-functional-component
reactjs - How to use state in this functional component? - Stack Overflow
See the hooks doc. and don't forget to add process.env.PUBLIC_URL (see my answer below) ... import React, {useState} from "react"; import Slider from 'react-slick'; import 'slick-carousel/slick/slick.css'; import 'slick-carousel/slick/slick-theme.css'; import "./style.css"; export default function ProductSlider { const [items, setItems] = useState([ {id:1 , image: 'behesht_rich_dadpoordad637253469910551640thum.jpg' , productName: 'پدرپولدار پدر بی پول' , oldPrice: '50000' , price: '40000'}, {id:1 , image: 'behesht_rich_dadpoordad637253469910551640thum.jpg' , productName: 'پد