useValue

React hooks for the @corets/value package.

Source code is hosted on GitHub

yarn add @corets/use-value

This is a React integration for this package:

Value

useValue()

Use observable values inside React components:

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

const globalValue = createValue(0)

const Example = () => {
  const value1 = useValue(0)
  const value2 = useValue(() => 0)
  const value3 = useValue(globalValue)
  
  // alternative syntax
  const [value, setValue] = useValue(globalValue).use()
  
  const increment = () => value1.set(value1.get() + 1)
  
  return <button onClick={increment}>Count: {value1.get()}</button>
}

Last updated