1.0.1 • Published 3 years ago

@feca-hooks/use-input v1.0.1

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

@feca-hooks/use-input

React Hook to create input element faster.

How to Install

yarn

yarn add @feca-hooks/use-input

npm

npm i @feca-hooks/use-input

Usage

Code

import React from "react";
import useInput from "@feca-hooks/use-input";

function App() {
  // validator must return true/false.
  const validator = () => {
    if (value.length > 10) return false;

    return true;
  }

  const { value, onChange } = useInput("", validator);

  return <input type="text" onChange={onChange} />;
}

Arguments

ArgumentTypeDescriptionRequired
defaultValuestringDefault value of the input text.no
validatorfunctionThe callback function validate the input value can change.no

Return

Return valueTypeDescription
Value StateobjectAn object containing the value, onChange. value is current input value. onChange is event function executes when input value has changed.
1.0.1

3 years ago

1.0.0

3 years ago