1.0.3 • Published 4 years ago

use-cep-hook v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

use-cep-hook :earth_americas: npm

This is a simple React Hooks that let you search for a brazillian postal-code on: https://viacep.com.br.

Installation

Just run a yarn add use-cep-hook or npm i --save use-cep-hook

How to use

Simply import use-cep-hook on your component, then call this on that way:

import useViaCep from "use-cep-hook";

const Foo = () => {
  const [postalCode, setPostalCode] = useState("");

  const [loading, cep, error] = useViaCep(postalCode);

  return (
    <div className="field">
      <label>CEP:</label>
      <input onChange={e => setPostalCode(e.target.value)} value={postalCode} />
    </div>
  );
};

Every time that the argument passed to the hooks get a length of 8, this will trigger a call to the API, changing the loading param to true.

TODO:

  • Port to TS
  • Apply some cool CSS to example
  • Write TESTS!
  • Deploy example to surge.sh!
  • Configure Github Actions