4.0.0 • Published 3 years ago

@bytesoftio/use-value v4.0.0

Weekly downloads
14
License
MIT
Repository
github
Last release
3 years ago

@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>
}
4.0.0

3 years ago

3.0.0

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago