8000 GitHub - FilipeGundim/use-cep-hook: Get info from https://viacep.com.br on a elegant way
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

FilipeGundim/use-cep-hook

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Get info from https://viacep.com.br on a elegant way

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 78.9%
  • HTML 17.1%
  • CSS 4.0%
0