@bytesoftio/use-value
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

@bytesoftio/use-value

Installation

yarn add @bytesoftio/use-value or npm install @bytesoftio/use-value

Table of contents

Description

This package provides a React integration for @bytesoftio/value.

useValue

This helper can be used to hook up a value inside a component.

import React from "react"
import { createValue } from "@bytesoftio/value"
import { useValue } from "@bytesoftio/use-value"

const globalCount = createValue(0)

const Component = () => {
  // hook up a new value, creates a new instance of ObservableValue behind the scenes
  const count1 = useValue(0)
  // use an initializer / factory
  const count2 = useValue(() => 0)
  // use an existing instance of ObservableValue
  const count3 = useValue(globalCount)
  
  const increment = () => count1.set(count1 + 1)

  return <button onClick={increment}>count: {count1.get()}</button>
}

Readme

Keywords

none

Package Sidebar

Install

npm i @bytesoftio/use-value

Weekly Downloads

2

Version

4.0.0

License

MIT

Unpacked Size

4.86 kB

Total Files

12

Last publish

Collaborators

  • maximkott