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

1.0.2 • Public • Published

use-value

A custom React hook that wraps the existing useState to be used similarly to jQuery's .val().

Usage

import { useValue } from '@cheesebit/use-value';

function CollapseSample() {
  const collapsed = useValue(false)

  return (
    <div>
      {collapsed() ? 'ON' : 'OFF'}
      <button
        type="button"
        onClick={() => {
          collapsed(!collapsed())
        }}
      >
        Toggle like this
      </button>
      <button
        type="button"
        onClick={() => {
          collapsed(isCollapsed => !isCollapsed)
        }}
      >
        Or like this
      </button>
    </div>
  )
}

Package Sidebar

Install

npm i @cheesebit/use-value

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

4.57 kB

Total Files

8

Last publish

Collaborators

  • welingtonms