# Value

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

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

```bash
yarn add @corets/value
```

{% endtab %}

{% tab title="npm" %}

```bash
npm install --save @corets/value
```

{% endtab %}
{% endtabs %}

Seamless React integration is shipped in a separate package:

{% content-ref url="/pages/-MeeCjonF5MnSCR9TohM" %}
[useValue](/hooks/use-value.md)
{% endcontent-ref %}

These packages provide extended functionality and are built on top of this library:

{% content-ref url="/pages/-MeeBQ0F094TDCsvnMbA" %}
[Store](/observables/store.md)
{% endcontent-ref %}

{% content-ref url="/pages/-MeeBIuqvkAwUjx0ORFs" %}
[List](/observables/list.md)
{% endcontent-ref %}

{% content-ref url="/pages/-MeeEDpap1iIyRi7d5Py" %}
[Local Storage Value](/observables/local-storage-value.md)
{% endcontent-ref %}

{% content-ref url="/pages/-MeeEM7lap525qmHR0yU" %}
[Local Storage Store](/observables/local-storage-store.md)
{% endcontent-ref %}

{% content-ref url="/pages/-MeeEJek1b6Kf63VvtQ5" %}
[Local Storage List](/observables/local-storage-list.md)
{% endcontent-ref %}

## createValue()

Create a new observable value:

```typescript
import { createValue } from "@corets/value"

const count = createValue(0)
```

Create a new observable value without the factory function:

```typescript
import { Value } from "@corets/value"

const value = new Value(0)
```

Create a new observable value with a custom differ:

```typescript
import { createValue } from "@corets/value"

const differ = (oldValue, newValue) => true
const count = createValue(0, { differ })
```

## Value.get()

Get current value:

```typescript
value.get()
```

## Value.set()

Update current value:

```typescript
value.set("new value")
```

## Value.listen()

Listen to value changes:

```typescript
const unsubscribe = value.listen((value) => console.log(value))

unsubscribe()
```

Invoke listener immediately:

```typescript
value.listen((value) => console.log(value), { immediate: true })
```

Listen with a custom differ:

```typescript
const differ = (oldValue, newValue) => true

value.listen((value) => console.log(value), { differ })
```

## Value.use()

Convenience method for people used to React's `useState` syntax:

```typescript
import { createValue } from "@corets/value"

const [value, setValue] = createValue(1).use()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.corets.io/observables/value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
