Search…
⌃K

Value

Simple value that can be hooked into React.
Source code is hosted on GitHub
yarn
npm
yarn add @corets/value
npm install --save @corets/value
Seamless React integration is shipped in a separate package:
These packages provide extended functionality and are built on top of this library:

createValue()

Create a new observable value:
import { createValue } from "@corets/value"
const count = createValue(0)
Create a new observable value without the factory function:
import { Value } from "@corets/value"
const value = new Value(0)
Create a new observable value with a custom differ:
import { createValue } from "@corets/value"
const differ = (oldValue, newValue) => true
const count = createValue(0, { differ })

Value.get()

Get current value:
value.get()

Value.set()

Update current value:
value.set("new value")

Value.listen()

Listen to value changes:
const unsubscribe = value.listen((value) => console.log(value))
unsubscribe()
Invoke listener immediately:
value.listen((value) => console.log(value), { immediate: true })
Listen with a custom differ:
const differ = (oldValue, newValue) => true
value.listen((value) => console.log(value), { differ })

Value.use()

Convenience method for people used to React's useState syntax:
import { createValue } from "@corets/value"
const [value, setValue] = createValue(1).use()