# @malda/use-prev-state

> `usePrevState` is a React utility package designed to simplify state management in functional components. This package provides a custom hook, `usePrevState`, which allows developers to effortlessly track and store the previous state values of their compo

Latest version **1.0.0** (published 2023-12-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install @malda/use-prev-state
pnpm add @malda/use-prev-state
yarn add @malda/use-prev-state
bun add @malda/use-prev-state
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-12-07 |
| First published | 2023-12-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Malda Motuma |
| Maintainers | malda.motuma |
| Keywords | useState, usePrevious, React, Nextjs, hooks, react hooks, Nextjs hooks |

## Links

- npm: https://www.npmjs.com/package/@malda/use-prev-state
- Repository: https://github.com/maldamotuma/usePrevState
- Homepage: https://github.com/maldamotuma/usePrevState#readme
- Issues: https://github.com/maldamotuma/usePrevState/issues
- npm.io page: https://npm.io/package/@malda/use-prev-state

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-12-07

## README

## Introduction
`usePrevState` is a React utility package designed to simplify state management in functional components. This package provides a custom hook, `usePrevState`, which allows developers to effortlessly track and store the previous state values of their components. By seamlessly integrating into both hook-based and traditional components, `usePrevState` enhances the predictability and efficiency of state changes, offering a straightforward solution for developers seeking more robust state management in their React applications.

## A Guide on Implementing usePrevState in React Applications

    import { usePrevState } from  "@malda/usePrevState";
    import {useState} from  "react";
    
      
    
    const  MyComponent = () => {
    const [state, setState] = useState<number>(0);
    const  prevState = usePrevState<number>(state);
    return (
	    <div>
		    <p>Previous Value : <strong>{prevState}</strong></p>
		    <p>Current Value : <strong>{state}</strong></p>
		    <button  onClick={() =>  setState(state + 1)}>plus</button>
		    <button  onClick={() =>  setState(state - 1)}>minus</button>
	    </div>
    )
    
    }

---
_Source: https://npm.io/package/@malda/use-prev-state · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
