> For the complete documentation index, see [llms.txt](https://docs.corets.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.corets.io/hooks/use-previous.md).

# usePrevious

Source code is hosted on [GitHub](https://github.com/corets/use-previous)

{% tabs %}
{% tab title="yarn" %}

```bash
yarn add @corets/use-previous
```

{% endtab %}

{% tab title="npm" %}

```
npm install --save @corets/use-previous
```

{% endtab %}
{% endtabs %}

## usePrevious() <a href="#useprevious" id="useprevious"></a>

Get the previous version of a value:

```typescript
import React, { useState } from "react"
import { usePrevious } from "@corets/use-previous"

const Example = () => {
  const [count, setCount] = useState(0)
  const previousCount = usePrevious(count)
  
  return (
    <div>
      <div>count: {count}</div>
      <div>previous count: {previousCount}</div>
    </div>
  )
}
```
