# @bytesoftio/value

> ## Installation

Latest version **3.0.0** (published 2020-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bytesoftio/value
pnpm add @bytesoftio/value
yarn add @bytesoftio/value
bun add @bytesoftio/value
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2020-11-26 |
| First published | 2020-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maxim Kott |
| Maintainers | maximkott |

## Links

- npm: https://www.npmjs.com/package/@bytesoftio/value
- Repository: https://github.com/bytesoftio/value
- npm.io page: https://npm.io/package/@bytesoftio/value

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15

## Recent versions

- 3.0.0 (latest) — 2020-11-26
- 2.0.5 — 2020-09-28
- 2.0.4 — 2020-09-22
- 2.0.3 — 2020-07-20
- 2.0.2 — 2020-05-03
- 2.0.1 — 2020-05-01
- 2.0.0 — 2020-05-01

## README

# @bytesoftio/value

## Installation

`yarn add @bytesoftio/value or `npm install `@bytesoftio/value`

## Table of contents

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Description](#description)
- [createValue](#createvalue)
- [ObservableValue](#observablevalue)
- [Usage in React](#usage-in-react)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Description

This package provides a generic observable value that can be used in any environment. Additionally there is the [@bytesoftio/use-value](https://github.com/bytesoftio/use-value) package that provides a seemless integration with React hooks. This allows you to write services that would work inside React, leveraging its hooks api, but also outside of React. It provides a very simple, observable like object `ObservableValue`.

## createValue

Create a simple observable value that can be hooked into any functional component. Returns an instance of `ObservableValue`.

```ts
import { createValue } from "@bytesoftio/value"

const count = createValue(0)
```

##  ObservableValue

Whenever you create a new value through `createValue`, a new instance of `ObservableValue` is created behind the scenes. It provides some convenient methods for working with data.

```ts
import React from "react"
import { createValue } from "@bytesoftio/value"

const globalCount = createValue(0)

// get current value of 0
globalCount.get()

// change value to 3
globalCount.set(3)

// reset value back to its initial value of  0
globalCount.reset()

// change initial value to 2 and reset value
globalCount.reset(2)

// listen to value changes outside of React
globalCount.listen((value) => console.log(value))
```

## Usage in React

To learn how to use this package in combination with React, please refer to [@bytesoftio/use-value](https://github.com/bytesoftio/use-value) package.

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