use-cep-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

use-cep-hook 🌎 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

Package Sidebar

Install

npm i use-cep-hook

Weekly Downloads

4

Version

1.0.3

License

ISC

Unpacked Size

34.1 kB

Total Files

20

Last publish

Collaborators

  • mateusandrade