use-controllable-state

1.0.0 • Public • Published

use-controllable-state

A React custom hook for managing state in a controlled component.

NPM JavaScript Style Guide

Install

npm install --save use-controllable-state

Usage

import { FC } from 'react'
import { useControllableState } from 'use-controllable-state';

const Component: FC = (value: string, onChange) => {
  const [internalChanges, internalSetState] = useControllableState<string>(value, onChange);

  const handleClick = () => {
    internalSetState("example of internal change to controlled state");
  };

  return (
    <div>
      <button onClick={handleClick}>Change state internally</button>
      <div>Last internal state change: {internalChanges}</div>
      <div>Controlled state: {value}</div>
    </div>
  );
};

License

MIT © RichieMillennium

Readme

Keywords

none

Package Sidebar

Install

npm i use-controllable-state

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.26 kB

Total Files

3

Last publish

Collaborators

  • richiemillennium