---
description: Track previous versions of values.
---

# 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>
  )
}
```
