/use-value

A custom React hook to set/get state using a single function.

Primary LanguageTypeScriptMIT LicenseMIT

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