Skip to content

Latest commit

 

History

History
38 lines (32 loc) · 973 Bytes

README.md

File metadata and controls

38 lines (32 loc) · 973 Bytes

use-value

Coverage Status npm package

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>
  );
}