LogoLogo
  • Home
  • Services
    • Fiber
    • Accessor
    • Schema
    • Form
    • Translator
  • Components
    • <Router/>
    • <Memo />
  • Observables
    • Async
    • Value
    • Store
    • List
    • Local Storage Value
    • Local Storage Store
    • Local Storage List
  • Hooks
    • useAsync
    • useAffect
    • useStream
    • useAction
    • useDebounce
    • useThrottle
    • usePrevious
    • useIdle
    • useValue
    • useList
    • useStore
    • useForm
    • useFormBinder
    • useTranslator
    • useQuery
  • Helpers
    • Tag
    • Input Helpers
    • Promise Helpers
    • Save Helpers
    • Pagination Helpers
    • Clipboard Helpers
    • Calendar Helpers
    • Local Storage Helpers
Powered by GitBook
On this page
  • createValue()
  • Value.get()
  • Value.set()
  • Value.listen()
  • Value.use()

Was this helpful?

  1. Observables

Value

Simple value that can be hooked into React.

PreviousAsyncNextStore

Last updated 3 years ago

Was this helpful?

Source code is hosted on

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()
GitHub
useValue
Store
List
Local Storage Value
Local Storage Store
Local Storage List