# urs

> 🔥 React hook for maintaining correct values, in a clean way

Latest version **0.0.8** (published 2021-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install urs
pnpm add urs
yarn add urs
bun add urs
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2021-03-09 |
| First published | 2020-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Alex Cory |
| Maintainers | alex-cory |
| Keywords | ssr, nextjs, server, server side rendering, server side, client, browser, isomorphic, react, react-hook, hooks, react hooks |

## Links

- npm: https://www.npmjs.com/package/urs
- Repository: https://github.com/alex-cory/urs
- Homepage: https://github.com/ava/urs#readme
- Issues: https://github.com/alex-cory/urs/issues
- npm.io page: https://npm.io/package/urs

## 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

- 0.0.8 (latest) — 2021-03-09
- 0.0.7 — 2020-05-13
- 0.0.6 — 2020-05-13
- 0.0.5 — 2020-04-17
- 0.0.4 — 2020-04-16
- 0.0.3 — 2020-04-16
- 0.0.2 — 2020-04-16
- 0.0.1 — 2020-04-16

## README

<h1 align="center">useRefState</h1>
<p align="center">🔥 React hook for maintaining correct values, in a clean way, without updates on unmounted components</p>
<p align="center">
    <a href="https://github.com/alex-cory/urs/pulls">
      <img src="https://camo.githubusercontent.com/d4e0f63e9613ee474a7dfdc23c240b9795712c96/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e737667" />
    </a>
    <a href="https://www.npmjs.com/package/urs">
      <img src="https://img.shields.io/npm/dt/urs.svg" />
    </a>
    <a href="https://bundlephobia.com/result?p=urs">
      <img alt="undefined" src="https://img.shields.io/bundlephobia/minzip/urs.svg">
    </a>
    <!-- <a href="https://github.com/alex-cory/urs/blob/master/license.md">
      <img alt="undefined" src="https://img.shields.io/github/license/alex-cory/urs.svg">
    </a> -->
    <a href="https://codeclimate.com/github/alex-cory/urs/maintainability">
      <img src="https://api.codeclimate.com/v1/badges/e661bf6aa5e4d64502c6/maintainability" />
    </a>
    <a href="https://www.npmjs.com/package/urs">
      <img src="https://img.shields.io/npm/v/urs.svg" style="max-width:100%;">
    </a>
</p>

Features
--------

- TypeScript support
- Zero dependencies
- React Native support
- Keep your state consistant within your callback functions

<!-- ### Examples
- [Example - Next.js - codesandbox container](https://codesandbox.io/s/rs-in-nextjs-actual-epb25) (sometimes containers are buggy, if so try [this example](https://codesandbox.io/s/rs-in-nextjs-4gy7v)) -->

Installation
------------

```shell
yarn add urs      or     npm i -S urs
```

Usage
-----

```jsx
import useRefState from 'urs'
import { useState } from 'react'

const App = () => {
  const [loadingRef, setLoadingRef] = useRefState(false)
  const [loadingState, setLoadingState] = useState(false)
  
  // DO NOT destructure like this
  const [{ current }] = useRefState()
  
  const onClick = () => {
    setLoadingRef(true)
    console.log('loadingRef.current', loadingRef.current) // gives us `true`
    setLoadingState(true)
    console.log('loadingState', loadingState) // gives us `false`
  }

  return (
    <button onClick={handleClick}>Click Me!</button>
  )
}
```

Options
-------

The 2nd argument of `useRefState` determines if you want to be able to update state when a component
is unmounted. If `true` it will block setState on unmounted components. Useful for the common error `cannot update state on unmounted component`.

```js
const [state, setState] = useRefState('same as useState default state', true)
```

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