---
title: "Discussion on \"How to use useState in React to update state based on previous value?\" | Hashnode"
description: "Discussion on \"How to use useState in React to update state based on previous value?\". use useState to update state based on previous state"
url: "https://hashnode.com/posts/how-to-use-usestate-in-react-to-update-state-based-on-previous-value/640a7d66b409bec797470a20"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to use useState in React to update state based on previous value?](https://slytherindor.hashnode.dev/how-to-use-usestate-in-react-to-update-state-based-on-previous-value?utm_source=hashnode&utm_medium=feed)

use useState to update state based on previous state

Mar 10, 2023 · 3 min read · slytherindor.hashnode.dev  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#usestate](https://hashnode.com/tag/usestate)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Shubhanshu](https://hashnode.com/@slytherindor)

@slytherindor · Ottawa

  
[View profile](https://hashnode.com/@slytherindor)

build -> fail -> iterate -> succeed

here to build things

## Responses 2

Markdown supported · ⌘↵ to post

[mahi kaushik](https://hashnode.com/@mahikaushik)

[Mar 28, 2023](https://hashnode.com/posts/how-to-use-usestate-in-react-to-update-state-based-on-previous-value/640a7d66b409bec797470a20/comment/642283b366aa3f8316eb330e)

Great question! To update the state based on its previous value, you can use the useState hook in React. The useState hook returns an array with two elements - the current state value and a function to update it. To update the state based on its previous value, you can pass a function to the update function instead of a new value. The function receives the previous state as its argument and returns the new state value. This way, you can ensure that the state is updated correctly even if multiple updates are happening simultaneously. For more information on using useState in React, you can check out this React useState blog. Thanks for asking! [copycat.dev/blog/react-usestate-hook](https://www.copycat.dev/blog/react-usestate-hook/)

[Abdirahman Farah Omar](https://hashnode.com/@AbdirahmanManka2030)

[Mar 10, 2023](https://hashnode.com/posts/how-to-use-usestate-in-react-to-update-state-based-on-previous-value/640a7d66b409bec797470a20/comment/640ad337e3de6419e7484ca1)

Good explanation to React useState hook
