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

1.0.3 • 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 '@welingtonms/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 @welingtonms/use-value

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

4.5 kB

Total Files

7

Last publish

Collaborators

  • welingtonms