1.1.0 • Published 5 years ago

react-hooks-inputs v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

React hooks inputs

Set of hooks to manage your inputs.

Import

yarn add react react-hooks-inputs
# or
npm i react react-hooks-inputs

Import

import {
  useCheckbox,
  useRadio,
  useSelect,
  useTextInput
} from "react-hooks-inputs";

Usage

useCheckbox

() => {
  const checkbox = useCheckbox({ state: true });
  return <input {...checkbox}>;
}

useRadio

() => {
  const radio = useRadio({ state: 'B' });
  return (
    <Fragment>
      <label htmlFor="A">A</label>
      <input {...radio('A')} id="A">
      <label htmlFor="B">B</label>
      <input {...radio('B')} id="B">
      <label htmlFor="C">C</label>
      <input {...radio('C')} id="C">
    </Fragment>
  )
};

useSelect

() => {
  const select = useSelect({ state: "A" });

  return (
    <select {...select}>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
    </select>
  );
};

useTextInput

() => {
  const textInput = useTextInput({ state: "" });

  return <input {...textInput} />;
};

Licence

MIT

1.1.0

5 years ago

1.0.0

5 years ago